summaryrefslogtreecommitdiff
path: root/apps/web/src/app/api/waitlist/token/route.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-07-20 16:36:21 +0200
committerMaze Winther <mazewinther@gmail.com>2025-07-20 16:36:21 +0200
commitba3da43728bc051aa033dc7b45042b0f0f788e63 (patch)
tree6039c0ddd5b19c7ecbcfbc6635e2495d85bd948b /apps/web/src/app/api/waitlist/token/route.ts
parentafa8f426fbe8617980d848cdda977f2ab47b5e4e (diff)
parentbaaf773b809674c07b4ab17ae3098abd768050ab (diff)
downloadopencut-ba3da43728bc051aa033dc7b45042b0f0f788e63.tar.gz
Merge branch 'staging'
Diffstat (limited to 'apps/web/src/app/api/waitlist/token/route.ts')
-rw-r--r--apps/web/src/app/api/waitlist/token/route.ts75
1 files changed, 30 insertions, 45 deletions
diff --git a/apps/web/src/app/api/waitlist/token/route.ts b/apps/web/src/app/api/waitlist/token/route.ts
index 6f5ee18f..4c7695fa 100644
--- a/apps/web/src/app/api/waitlist/token/route.ts
+++ b/apps/web/src/app/api/waitlist/token/route.ts
@@ -5,57 +5,42 @@ import { env } from "@/env";
const CSRF_TOKEN_NAME = "waitlist-csrf";
const TOKEN_EXPIRY = 60 * 60 * 1000;
-const allowedHosts =
- env.NODE_ENV === "development"
- ? ["localhost:3000", "127.0.0.1:3000"]
- : ["opencut.app", "www.opencut.app"];
+const allowedHosts = env.NODE_ENV === "development" ? ["localhost:3000", "127.0.0.1:3000"] : ["opencut.app", "www.opencut.app"];
export async function GET(request: NextRequest) {
- const referer = request.headers.get("referer");
- const host = request.headers.get("host");
+ const referer = request.headers.get("referer");
+ const host = request.headers.get("host");
- if (referer) {
- const refererUrl = new URL(referer);
+ if (referer) {
+ const refererUrl = new URL(referer);
- if (
- !allowedHosts.some(
- (allowed) =>
- refererUrl.host === allowed || refererUrl.host.endsWith(allowed),
- )
- ) {
- return NextResponse.json({ error: "Forbidden" }, { status: 403 });
- }
- } else if (host) {
- if (
- !allowedHosts.some(
- (allowed) => host === allowed || host.endsWith(allowed),
- )
- ) {
- return NextResponse.json({ error: "Forbidden" }, { status: 403 });
- }
- } else {
- return NextResponse.json({ error: "Forbidden" }, { status: 403 });
- }
+ if (!allowedHosts.some((allowed) => refererUrl.host === allowed || refererUrl.host.endsWith(allowed))) {
+ return NextResponse.json({ error: "Forbidden" }, { status: 403 });
+ }
+ } else if (host) {
+ if (!allowedHosts.some((allowed) => host === allowed || host.endsWith(allowed))) {
+ return NextResponse.json({ error: "Forbidden" }, { status: 403 });
+ }
+ } else {
+ return NextResponse.json({ error: "Forbidden" }, { status: 403 });
+ }
- if (!env.BETTER_AUTH_SECRET) {
- throw new Error("BETTER_AUTH_SECRET must be configured");
- }
+ if (!env.BETTER_AUTH_SECRET) {
+ throw new Error("BETTER_AUTH_SECRET must be configured");
+ }
- const token = crypto.randomBytes(32).toString("hex");
- const timestamp = Date.now();
- const signature = crypto
- .createHmac("sha256", env.BETTER_AUTH_SECRET)
- .update(`${token}:${timestamp}`)
- .digest("hex");
+ const token = crypto.randomBytes(32).toString("hex");
+ const timestamp = Date.now();
+ const signature = crypto.createHmac("sha256", env.BETTER_AUTH_SECRET).update(`${token}:${timestamp}`).digest("hex");
- const cookieStore = await cookies();
- cookieStore.set(CSRF_TOKEN_NAME, `${token}:${timestamp}:${signature}`, {
- httpOnly: true,
- secure: env.NODE_ENV === "production",
- sameSite: "strict",
- maxAge: TOKEN_EXPIRY / 1000,
- path: "/",
- });
+ const cookieStore = await cookies();
+ cookieStore.set(CSRF_TOKEN_NAME, `${token}:${timestamp}:${signature}`, {
+ httpOnly: true,
+ secure: env.NODE_ENV === "production",
+ sameSite: "strict",
+ maxAge: TOKEN_EXPIRY / 1000,
+ path: "/",
+ });
- return NextResponse.json({ token });
+ return NextResponse.json({ token });
}