ai_api / src /app /api /auth /status /route.ts
Yogesh
initial deploy
cd8bd0a
Raw
History Blame Contribute Delete
705 Bytes
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import { jwtVerify } from "jose";
function getJwtSecret(): Uint8Array | null {
const secret = process.env.JWT_SECRET?.trim();
return secret ? new TextEncoder().encode(secret) : null;
}
export async function GET() {
try {
const cookieStore = await cookies();
const token = cookieStore.get("auth_token")?.value;
const secret = getJwtSecret();
if (!token || !secret) {
return NextResponse.json({ authenticated: false });
}
await jwtVerify(token, secret);
return NextResponse.json({ authenticated: true });
} catch {
return NextResponse.json({ authenticated: false });
}
}