fix: minor auth fix

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj committed 2024-09-03 08:20:19 +05:30
1 parent fac694b3fd
commit 707876825e
7 files changed
+13 -3

No files matched your search

+1
View File
@@ -40,6 +40,7 @@ export const getCurrentUser = async (req: NextApiRequest) => {
if (session) { if (session) {
const user = await getCurrentUserFromAccessToken(session) const user = await getCurrentUserFromAccessToken(session)
if (!user) return null
return { return {
...user, ...user,
accessToken: session, accessToken: session,
@@ -36,6 +36,7 @@ const SELECT_ORPHAN_PHOTOS = (date: string, ownerId: string) =>
aaa."albumsId" IS NULL aaa."albumsId" IS NULL
AND a."ownerId" = '${ownerId}' AND a."ownerId" = '${ownerId}'
AND a."localDateTime"::date = '${date}' AND a."localDateTime"::date = '${date}'
AND a."isVisible" = true
`); `);
export default async function handler( export default async function handler(
@@ -17,6 +17,7 @@ LEFT JOIN
WHERE WHERE
aaa."albumsId" IS NULL aaa."albumsId" IS NULL
AND a."ownerId" = ${ownerId} AND a."ownerId" = ${ownerId}
AND a."isVisible" = true
GROUP BY GROUP BY
DATE(a."localDateTime") DATE(a."localDateTime")
ORDER BY ORDER BY
@@ -53,6 +53,7 @@ export default async function handler(
lte(exif.dateTimeOriginal, endDateDate), lte(exif.dateTimeOriginal, endDateDate),
eq(assets.type, "VIDEO"), eq(assets.type, "VIDEO"),
eq(assets.ownerId, currentUser.id), eq(assets.ownerId, currentUser.id),
eq(assets.isVisible, true),
)); ));
return res.status(200).json(rows); return res.status(200).json(rows);
@@ -23,6 +23,7 @@ export default async function handler(
isNull(exif.latitude), isNull(exif.latitude),
eq(assets.type, "VIDEO"), eq(assets.type, "VIDEO"),
eq(assets.ownerId, currentUser.id), eq(assets.ownerId, currentUser.id),
eq(assets.isVisible, true),
)) ))
.groupBy(sql`DATE(${exif.dateTimeOriginal})`) .groupBy(sql`DATE(${exif.dateTimeOriginal})`)
.orderBy(desc(count(assets.id))); .orderBy(desc(count(assets.id)));
@@ -1,6 +1,7 @@
// pages/api/proxy.js // pages/api/proxy.js
import { ENV } from '@/config/environment'; import { ENV } from '@/config/environment';
import { getCurrentUser } from '@/handlers/serverUtils/user.utils';
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
export const config = { export const config = {
@@ -17,13 +18,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { id, size } = req.query; const { id, size } = req.query;
const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/thumbnail?size=${size || 'thumbnail'}`; const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/thumbnail?size=${size || 'thumbnail'}`;
const user = await getCurrentUser(req);
if (!user) {
return res.status(403).json({ message: 'Unauthorized' })
}
try { try {
// Forward the request to the target API // Forward the request to the target API
const response = await fetch(targetUrl, { const response = await fetch(targetUrl, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/octet-stream', 'Content-Type': 'application/octet-stream',
'x-api-key': ENV.IMMICH_API_KEY, 'Authorization': `Bearer ${user.accessToken}`,
}, },
}) })
@@ -42,7 +47,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// Send the image data // Send the image data
res.send(Buffer.from(imageBuffer)) res.send(Buffer.from(imageBuffer))
} catch (error) { } catch (error) {
console.error('Error:', error)
res.status(500).json({ message: 'Internal Server Error' }) res.status(500).json({ message: 'Internal Server Error' })
} }
} }
+2 -1
View File
@@ -17,7 +17,8 @@ export default async function handler(
return res.status(405).json({ message: "Method Not Allowed" }); return res.status(405).json({ message: "Method Not Allowed" });
const user = getCurrentUser(req); const user = await getCurrentUser(req);
console.log("currentUser.accessToken:", user);
if (user) return res.status(200).json(user); if (user) return res.status(200).json(user);