2025-05-17 15:14:24 +02:00
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
import jwt from 'jsonwebtoken';
|
|
|
|
|
import prisma from "@/app/prisma";
|
|
|
|
|
|
|
|
|
|
interface Body {
|
|
|
|
|
token: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function POST(request: NextRequest) {
|
|
|
|
|
try {
|
|
|
|
|
const body: Body = await request.json();
|
|
|
|
|
|
|
|
|
|
if (!body.token) {
|
|
|
|
|
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!process.env.JWT_SECRET) {
|
|
|
|
|
return NextResponse.json({ error: "No JWT secret found" }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const decoded = jwt.verify(body.token, process.env.JWT_SECRET) as { id: string };
|
|
|
|
|
|
|
|
|
|
const user = await prisma.user.findUnique({
|
|
|
|
|
where: {
|
|
|
|
|
id: decoded.id,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-17 19:33:52 +02:00
|
|
|
return NextResponse.json({ message: "Valid", username: user.username, name: user.name }, { status: 200 });
|
2025-05-17 15:14:24 +02:00
|
|
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|