Files
gitlab-instance-0a899031_no…/app/api/auth/email/route.ts
2026-03-13 03:43:50 -05:00

20 lines
707 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 从 Cookie 读取邮箱(不调用 PB用于 emailLinked=1 但 userName 被覆盖的场景
*/
import { NextRequest, NextResponse } from "next/server";
import { COOKIE_NAME } from "@/app/lib/auth-cookie";
export async function GET(request: NextRequest) {
const cookie = request.cookies.get(COOKIE_NAME)?.value;
if (!cookie) {
return NextResponse.json({ ok: true, email: null });
}
try {
const payload = JSON.parse(Buffer.from(cookie, "base64url").toString("utf-8"));
const email = payload?.email ?? null;
return NextResponse.json({ ok: true, email: typeof email === "string" ? email : null });
} catch {
return NextResponse.json({ ok: true, email: null });
}
}