mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-28 19:05:31 +02:00
add auth to api routes
This commit is contained in:
parent
86d39a8616
commit
03e4d45bc3
4 changed files with 44 additions and 2 deletions
|
|
@ -1,10 +1,21 @@
|
|||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { S3Client, GetObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { Readable } from 'stream';
|
||||
import { authCheck } from '@/app/actions/auth.actions';
|
||||
import { USE_AUTH } from '@/app/lib/feature_flags';
|
||||
|
||||
// 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.
|
||||
export async function GET(request: NextRequest, props: { params: Promise<{ id: string }> }) {
|
||||
// Require authentication if enabled
|
||||
try {
|
||||
if (USE_AUTH) {
|
||||
await authCheck();
|
||||
}
|
||||
} catch (_) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const params = await props.params;
|
||||
const id = params.id;
|
||||
if (!id) {
|
||||
|
|
@ -72,4 +83,3 @@ export async function GET(request: NextRequest, props: { params: Promise<{ id: s
|
|||
return NextResponse.json({ error: 'Not found' }, { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue