31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { postMeetupApi } from "../_paymentApi";
|
|
|
|
const COOKIE_NEEDS_PW = "meetup_needs_password_change";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json().catch(() => ({}));
|
|
const email = String(body?.email || "").trim();
|
|
const password = String(body?.password || "").trim();
|
|
if (!email) {
|
|
return NextResponse.json({ ok: false, error: "Please enter your email" }, { status: 400 });
|
|
}
|
|
|
|
const { status, data } = await postMeetupApi(request, "/api/meetup/ensure-user", {
|
|
email,
|
|
password: password || undefined,
|
|
});
|
|
const payload = typeof data === "object" && data !== null ? data as Record<string, unknown> : null;
|
|
|
|
const nextRes = NextResponse.json(data, { status });
|
|
if (status >= 200 && status < 300 && payload?.is_new) {
|
|
nextRes.cookies.set(COOKIE_NEEDS_PW, "1", { path: "/", maxAge: 60 * 60 * 24 });
|
|
}
|
|
return nextRes;
|
|
} catch (error) {
|
|
console.error("ensure-user error:", error);
|
|
return NextResponse.json({ ok: false, error: "Operation failed" }, { status: 500 });
|
|
}
|
|
}
|