account settings and account creation
This commit is contained in:
@@ -1,22 +1,43 @@
|
||||
// app/api/beta-signup/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
const TOS_VERSION = "2025-12-27";
|
||||
|
||||
type BetaSignupBody = {
|
||||
email?: string;
|
||||
useCase?: string;
|
||||
acceptedTos?: boolean;
|
||||
tosVersion?: string;
|
||||
};
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const body = (await req.json()) as BetaSignupBody;
|
||||
|
||||
const email = (body.email ?? "").trim().toLowerCase();
|
||||
const useCase = (body.useCase ?? "").trim();
|
||||
const acceptedTos = Boolean(body.acceptedTos);
|
||||
const tosVersion = (body.tosVersion ?? TOS_VERSION).trim() || TOS_VERSION;
|
||||
|
||||
// Keep "no enumeration": always return ok:true, but silently refuse bad input
|
||||
if (!email || !acceptedTos) {
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
|
||||
// Forward only known fields
|
||||
const payload = { email, useCase, acceptedTos, tosVersion };
|
||||
|
||||
const res = await fetch(`${API_BASE_URL}/api/auth/beta/signup`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
body: JSON.stringify(payload),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
// Always return ok=true (matches your server behavior)
|
||||
if (!res.ok) {
|
||||
// Optional: log server response for debugging
|
||||
const text = await res.text().catch(() => "");
|
||||
console.error("beta-signup proxy failed:", res.status, text);
|
||||
}
|
||||
@@ -24,6 +45,6 @@ export async function POST(req: Request) {
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (e) {
|
||||
console.error("beta-signup proxy error:", e);
|
||||
return NextResponse.json({ ok: true }); // keep “no enumeration”
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const body = await req.text().catch(() => "");
|
||||
const auth = req.headers.get("authorization") ?? "";
|
||||
|
||||
const upstream = await fetch(`${API_BASE_URL}/api/v1/users/me/password`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": req.headers.get("content-type") ?? "application/json",
|
||||
...(auth ? { authorization: auth } : {}),
|
||||
},
|
||||
body,
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const text = await upstream.text().catch(() => "");
|
||||
return new NextResponse(text, {
|
||||
status: upstream.status,
|
||||
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
function passthroughHeaders(req: Request) {
|
||||
const h = new Headers();
|
||||
const auth = req.headers.get("authorization");
|
||||
if (auth) h.set("authorization", auth);
|
||||
h.set("content-type", req.headers.get("content-type") ?? "application/json");
|
||||
return h;
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const upstream = await fetch(`${API_BASE_URL}/api/v1/users/me`, {
|
||||
method: "GET",
|
||||
headers: passthroughHeaders(req),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const text = await upstream.text().catch(() => "");
|
||||
return new NextResponse(text, {
|
||||
status: upstream.status,
|
||||
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function PATCH(req: Request) {
|
||||
const body = await req.text().catch(() => "");
|
||||
|
||||
const upstream = await fetch(`${API_BASE_URL}/api/v1/users/me`, {
|
||||
method: "PATCH",
|
||||
headers: passthroughHeaders(req),
|
||||
body,
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const text = await upstream.text().catch(() => "");
|
||||
return new NextResponse(text, {
|
||||
status: upstream.status,
|
||||
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const url = new URL(req.url);
|
||||
const username = url.searchParams.get("username") ?? "";
|
||||
const auth = req.headers.get("authorization") ?? "";
|
||||
|
||||
const upstream = await fetch(
|
||||
`${API_BASE_URL}/api/v1/users/me/username-available?username=${encodeURIComponent(username)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
...(auth ? { authorization: auth } : {}),
|
||||
},
|
||||
cache: "no-store",
|
||||
}
|
||||
);
|
||||
|
||||
const text = await upstream.text().catch(() => "");
|
||||
return new NextResponse(text, {
|
||||
status: upstream.status,
|
||||
headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user