Reintroduce server-side auth
This commit is contained in:
parent
a510526e71
commit
4f7fd64f9e
@ -1,3 +1,4 @@
|
|||||||
|
import { auth } from '@/auth';
|
||||||
import { getImageCacheHeadersForAuth } from '@/cache';
|
import { getImageCacheHeadersForAuth } from '@/cache';
|
||||||
import PhotoOGImageResponse from '@/photo/image-response/PhotoOGImageResponse';
|
import PhotoOGImageResponse from '@/photo/image-response/PhotoOGImageResponse';
|
||||||
import { getPhoto } from '@/services/postgres';
|
import { getPhoto } from '@/services/postgres';
|
||||||
@ -10,7 +11,7 @@ export const runtime = 'edge';
|
|||||||
export async function GET(request: Request, context: any) {
|
export async function GET(request: Request, context: any) {
|
||||||
const photo = await getPhoto(context.params.photoId);
|
const photo = await getPhoto(context.params.photoId);
|
||||||
const fontData = await getIBMPlexMonoMedium();
|
const fontData = await getIBMPlexMonoMedium();
|
||||||
const headers = await getImageCacheHeadersForAuth();
|
const headers = await getImageCacheHeadersForAuth(await auth());
|
||||||
|
|
||||||
if (!photo) { return null; }
|
if (!photo) { return null; }
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { auth } from '@/auth';
|
||||||
import { getImageCacheHeadersForAuth } from '@/cache';
|
import { getImageCacheHeadersForAuth } from '@/cache';
|
||||||
import DeployImageResponse from '@/photo/image-response/DeployImageResponse';
|
import DeployImageResponse from '@/photo/image-response/DeployImageResponse';
|
||||||
import { getPhotos } from '@/services/postgres';
|
import { getPhotos } from '@/services/postgres';
|
||||||
@ -9,7 +10,7 @@ export const runtime = 'edge';
|
|||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const photos = await getPhotos('priority');
|
const photos = await getPhotos('priority');
|
||||||
const fontData = await getIBMPlexMonoMedium();
|
const fontData = await getIBMPlexMonoMedium();
|
||||||
const headers = await getImageCacheHeadersForAuth();
|
const headers = await getImageCacheHeadersForAuth(await auth());
|
||||||
|
|
||||||
return new ImageResponse(
|
return new ImageResponse(
|
||||||
(
|
(
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { auth } from '@/auth';
|
||||||
import { getImageCacheHeadersForAuth } from '@/cache';
|
import { getImageCacheHeadersForAuth } from '@/cache';
|
||||||
import DeployImageResponse from '@/photo/image-response/DeployImageResponse';
|
import DeployImageResponse from '@/photo/image-response/DeployImageResponse';
|
||||||
import { getPhotos } from '@/services/postgres';
|
import { getPhotos } from '@/services/postgres';
|
||||||
@ -10,7 +11,7 @@ export const runtime = 'edge';
|
|||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const photos = await getPhotos('priority');
|
const photos = await getPhotos('priority');
|
||||||
const fontData = await getIBMPlexMonoMedium();
|
const fontData = await getIBMPlexMonoMedium();
|
||||||
const headers = await getImageCacheHeadersForAuth();
|
const headers = await getImageCacheHeadersForAuth(await auth());
|
||||||
|
|
||||||
return new ImageResponse(
|
return new ImageResponse(
|
||||||
(
|
(
|
||||||
|
|||||||
5
src/cache/index.ts
vendored
5
src/cache/index.ts
vendored
@ -1,4 +1,5 @@
|
|||||||
import { getPhoto, getPhotos } from '@/services/postgres';
|
import { getPhoto, getPhotos } from '@/services/postgres';
|
||||||
|
import type { Session } from 'next-auth/types';
|
||||||
import { revalidatePath, revalidateTag, unstable_cache } from 'next/cache';
|
import { revalidatePath, revalidateTag, unstable_cache } from 'next/cache';
|
||||||
|
|
||||||
const TAG_PHOTOS = 'photos';
|
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 {
|
return {
|
||||||
'Cache-Control': shouldCache
|
'Cache-Control': !session?.user
|
||||||
? 's-maxage=3600, stale-while-revalidate'
|
? 's-maxage=3600, stale-while-revalidate'
|
||||||
: 's-maxage=1, stale-while-revalidate',
|
: 's-maxage=1, stale-while-revalidate',
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user