This commit is contained in:
Zacharias-Brohn
2026-01-14 20:02:17 +01:00
parent 8ddd4e47ec
commit f5197d92f7
14 changed files with 10823 additions and 13030 deletions
+18 -1
View File
@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { jwtVerify } from 'jose';
import { prisma } from '@/lib/prisma';
const JWT_SECRET = new TextEncoder().encode(
process.env.JWT_SECRET || 'your-secret-key-at-least-32-chars-long'
@@ -14,7 +15,23 @@ export async function GET(request: NextRequest) {
try {
const { payload } = await jwtVerify(token, JWT_SECRET);
return NextResponse.json({ user: payload }, { status: 200 });
const userId = payload.userId as string;
// Fetch fresh user data from database to get current settings
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
username: true,
accentColor: true,
},
});
if (!user) {
return NextResponse.json({ user: null }, { status: 200 });
}
return NextResponse.json({ user }, { status: 200 });
} catch (error) {
return NextResponse.json({ user: null }, { status: 200 });
}
+48
View File
@@ -0,0 +1,48 @@
import { NextRequest, NextResponse } from 'next/server';
import { jwtVerify } from 'jose';
import { prisma } from '@/lib/prisma';
const JWT_SECRET = new TextEncoder().encode(
process.env.JWT_SECRET || 'your-secret-key-at-least-32-chars-long'
);
export async function PATCH(request: NextRequest) {
const token = request.cookies.get('token')?.value;
if (!token) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
try {
const { payload } = await jwtVerify(token, JWT_SECRET);
const userId = payload.userId as string;
const body = await request.json();
const { accentColor } = body;
if (accentColor !== undefined && typeof accentColor !== 'string') {
return NextResponse.json({ error: 'Invalid accentColor' }, { status: 400 });
}
const updateData: { accentColor?: string } = {};
if (accentColor !== undefined) {
updateData.accentColor = accentColor;
}
const updatedUser = await prisma.user.update({
where: { id: userId },
data: updateData,
select: {
id: true,
username: true,
accentColor: true,
},
});
return NextResponse.json(updatedUser, { status: 200 });
} catch (error) {
console.error('Update user settings error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}