added proper auth

This commit is contained in:
arkml 2025-09-26 17:11:12 +05:30
parent bf6d04c4ea
commit 58d83796c9

View file

@ -1,20 +1,13 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { S3Client, GetObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3'; import { S3Client, GetObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
import { Readable } from 'stream'; import { Readable } from 'stream';
import { authCheck } from '@/app/actions/auth.actions'; import { requireAuth } from '@/app/lib/auth';
import { USE_AUTH } from '@/app/lib/feature_flags';
// Serves uploaded images from S3 by UUID-only path: /api/uploaded-images/{id} // Serves uploaded images from S3 by UUID-only path: /api/uploaded-images/{id}
// Reconstructs the S3 key using the same sharding logic as image upload. // Reconstructs the S3 key using the same sharding logic as image upload.
export async function GET(request: NextRequest, props: { params: Promise<{ id: string }> }) { export async function GET(request: NextRequest, props: { params: Promise<{ id: string }> }) {
// Require authentication if enabled // Require authentication (handles guest mode internally when USE_AUTH is disabled)
try { await requireAuth();
if (USE_AUTH) {
await authCheck();
}
} catch (_) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const params = await props.params; const params = await props.params;
const id = params.id; const id = params.id;