17 lines
511 B
TypeScript
17 lines
511 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { cookies } from "next/headers";
|
|
|
|
const COOKIE = "sam_pruebas_alumno";
|
|
|
|
/** Alumno conectado (según cookie de sesión). */
|
|
export async function GET() {
|
|
const jar = await cookies();
|
|
const raw = jar.get(COOKIE)?.value;
|
|
if (!raw) return NextResponse.json({ user: null }, { status: 401 });
|
|
try {
|
|
return NextResponse.json({ user: JSON.parse(decodeURIComponent(raw)) });
|
|
} catch {
|
|
return NextResponse.json({ user: null }, { status: 401 });
|
|
}
|
|
}
|