diff --git a/src/app/(isr)/photos/[photoId]/image/route.tsx b/src/app/(isr)/photos/[photoId]/image/route.tsx index 986e67db..a2b26e0d 100644 --- a/src/app/(isr)/photos/[photoId]/image/route.tsx +++ b/src/app/(isr)/photos/[photoId]/image/route.tsx @@ -1,3 +1,4 @@ +import { auth } from '@/auth'; import { getImageCacheHeadersForAuth } from '@/cache'; import PhotoOGImageResponse from '@/photo/image-response/PhotoOGImageResponse'; import { getPhoto } from '@/services/postgres'; @@ -10,7 +11,7 @@ export const runtime = 'edge'; export async function GET(request: Request, context: any) { const photo = await getPhoto(context.params.photoId); const fontData = await getIBMPlexMonoMedium(); - const headers = await getImageCacheHeadersForAuth(); + const headers = await getImageCacheHeadersForAuth(await auth()); if (!photo) { return null; } diff --git a/src/app/(isr)/template-image-tight/route.tsx b/src/app/(isr)/template-image-tight/route.tsx index 494595f8..85893e29 100644 --- a/src/app/(isr)/template-image-tight/route.tsx +++ b/src/app/(isr)/template-image-tight/route.tsx @@ -1,3 +1,4 @@ +import { auth } from '@/auth'; import { getImageCacheHeadersForAuth } from '@/cache'; import DeployImageResponse from '@/photo/image-response/DeployImageResponse'; import { getPhotos } from '@/services/postgres'; @@ -9,7 +10,7 @@ export const runtime = 'edge'; export async function GET(request: Request) { const photos = await getPhotos('priority'); const fontData = await getIBMPlexMonoMedium(); - const headers = await getImageCacheHeadersForAuth(); + const headers = await getImageCacheHeadersForAuth(await auth()); return new ImageResponse( ( diff --git a/src/app/(isr)/template-image/route.tsx b/src/app/(isr)/template-image/route.tsx index c5348632..fa102f73 100644 --- a/src/app/(isr)/template-image/route.tsx +++ b/src/app/(isr)/template-image/route.tsx @@ -1,3 +1,4 @@ +import { auth } from '@/auth'; import { getImageCacheHeadersForAuth } from '@/cache'; import DeployImageResponse from '@/photo/image-response/DeployImageResponse'; import { getPhotos } from '@/services/postgres'; @@ -10,7 +11,7 @@ export const runtime = 'edge'; export async function GET(request: Request) { const photos = await getPhotos('priority'); const fontData = await getIBMPlexMonoMedium(); - const headers = await getImageCacheHeadersForAuth(); + const headers = await getImageCacheHeadersForAuth(await auth()); return new ImageResponse( ( diff --git a/src/cache/index.ts b/src/cache/index.ts index fbc39e31..2e0bb7cf 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -1,4 +1,5 @@ import { getPhoto, getPhotos } from '@/services/postgres'; +import type { Session } from 'next-auth/types'; import { revalidatePath, revalidateTag, unstable_cache } from 'next/cache'; const TAG_PHOTOS = 'photos'; @@ -41,9 +42,9 @@ export const getPhotoCached: typeof getPhoto = (...args) => } )(); -export const getImageCacheHeadersForAuth = async (shouldCache = true) => { +export const getImageCacheHeadersForAuth = async (session?: Session) => { return { - 'Cache-Control': shouldCache + 'Cache-Control': !session?.user ? 's-maxage=3600, stale-while-revalidate' : 's-maxage=1, stale-while-revalidate', };