20 lines
707 B
TypeScript
20 lines
707 B
TypeScript
/**
|
||
* 从 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 });
|
||
}
|
||
}
|