Initial commit - cleaned for CV
This commit is contained in:
28
app/api/sync/route.ts
Normal file
28
app/api/sync/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getDatabase, saveDatabase } from '@/lib/server-db';
|
||||
import { verifySession } from '@/lib/auth';
|
||||
|
||||
export async function GET() {
|
||||
const session = await verifySession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const data = getDatabase(session.username);
|
||||
return NextResponse.json(data);
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const session = await verifySession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
saveDatabase(session.username, body);
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Invalid Data' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user