Fix: Multi-user data isolation and Legacy migration logic

This commit is contained in:
ren
2026-01-29 15:03:07 +01:00
parent 020218275f
commit e5c9de2df5
5 changed files with 98 additions and 11 deletions

View File

@@ -1,15 +1,26 @@
import { NextResponse } from 'next/server';
import { getDatabase, saveDatabase } from '@/lib/server-db';
import { verifySession } from '@/lib/auth';
export async function GET() {
const data = getDatabase();
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(body);
saveDatabase(session.username, body);
return NextResponse.json({ success: true });
} catch (error) {
return NextResponse.json({ error: 'Invalid Data' }, { status: 400 });