beta sign up sends an email with a magic token. then a separate email to login.

This commit is contained in:
2025-12-20 17:15:10 -05:00
parent c06696e66d
commit 8d9013d0dd
8 changed files with 459 additions and 119 deletions
+13 -46
View File
@@ -1,61 +1,28 @@
import { NextResponse } from "next/server";
const BREVO_API_KEY = process.env.BREVO_API_KEY;
const BREVO_LIST_ID = process.env.BREVO_LIST_ID; // optional
const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
export async function POST(req: Request) {
if (!BREVO_API_KEY) {
console.error("BREVO_API_KEY is not set");
return NextResponse.json(
{ error: "Server not configured" },
{ status: 500 }
);
}
try {
const { email } = await req.json();
const body = await req.json();
if (!email || typeof email !== "string") {
return NextResponse.json(
{ error: "Valid email is required" },
{ status: 400 }
);
}
// Brevo contacts API
const res = await fetch("https://api.brevo.com/v3/contacts", {
const res = await fetch(`${API_BASE_URL}/api/auth/beta/signup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": BREVO_API_KEY,
},
body: JSON.stringify({
email,
updateEnabled: true, // update if already exists
...(BREVO_LIST_ID
? { listIds: [Number(BREVO_LIST_ID)] }
: {}),
attributes: {
SOURCE: "Battl Builders Beta",
},
}),
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
// Always return ok=true (matches your server behavior)
if (!res.ok) {
const text = await res.text();
console.error("Brevo error:", res.status, text);
return NextResponse.json(
{ error: "Failed to subscribe" },
{ status: 500 }
);
// Optional: log server response for debugging
const text = await res.text().catch(() => "");
console.error("beta-signup proxy failed:", res.status, text);
}
return NextResponse.json({ ok: true });
} catch (err) {
console.error(err);
return NextResponse.json(
{ error: "Something went wrong" },
{ status: 500 }
);
} catch (e) {
console.error("beta-signup proxy error:", e);
return NextResponse.json({ ok: true }); // keep “no enumeration”
}
}