23 lines
828 B
TypeScript
23 lines
828 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { COOKIE_NAME, getCookieOptions, getHostFromRequest } from "@/app/lib/auth-cookie";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const body = await request.json().catch(() => ({}));
|
|
const token = body?.token;
|
|
const record = body?.record;
|
|
if (!token || !record?.id) {
|
|
return NextResponse.json({ ok: false, error: "缺少 token 或 record" }, { status: 400 });
|
|
}
|
|
|
|
const payload = JSON.stringify({
|
|
token,
|
|
userId: record.id,
|
|
email: record.email ?? "",
|
|
});
|
|
const encoded = Buffer.from(payload, "utf-8").toString("base64url");
|
|
|
|
const res = NextResponse.json({ ok: true });
|
|
res.cookies.set(COOKIE_NAME, encoded, getCookieOptions(false, getHostFromRequest(request)) as Record<string, string | number | boolean>);
|
|
return res;
|
|
}
|