changes
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user