-
Notifications
You must be signed in to change notification settings - Fork 9
feat: waitlist supabase api #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aguilar1x
merged 3 commits into
ACTA-Team:develop
from
felipevega2x:feat/waitlist-supabase-api
Mar 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { NextResponse } from "next/server"; | ||
| import { getServiceSupabase } from "@/lib/supabase"; | ||
|
|
||
| const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
|
|
||
| interface WaitlistPayload { | ||
| email?: string; | ||
| company_name?: string; | ||
| use_case?: string; | ||
| } | ||
|
|
||
| export async function POST(request: Request) { | ||
| try { | ||
| const body = (await request.json()) as WaitlistPayload; | ||
|
|
||
| const email = body.email?.trim().toLowerCase(); | ||
| if (!email || !EMAIL_REGEX.test(email)) { | ||
| return NextResponse.json( | ||
| { error: "A valid email address is required." }, | ||
| { status: 400 } | ||
| ); | ||
| } | ||
|
|
||
| const company_name = body.company_name?.trim() || null; | ||
| const use_case = body.use_case?.trim() || null; | ||
|
|
||
| const supabase = getServiceSupabase(); | ||
|
|
||
| const { error } = await supabase | ||
| .from("waitlist") | ||
| .insert({ email, company_name, use_case }); | ||
|
|
||
| if (error) { | ||
| if (error.code === "23505") { | ||
| return NextResponse.json( | ||
| { error: "This email is already on the waitlist." }, | ||
| { status: 409 } | ||
| ); | ||
| } | ||
|
|
||
| console.error("[api/waitlist] Supabase error:", error.message); | ||
| return NextResponse.json( | ||
|
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging raw error messages that may include submitted email. Line 41 and Line 52 log raw error text/object. Database errors can contain duplicate key details with user email. 🔧 Proposed fix- console.error("[api/waitlist] Supabase error:", error.message);
+ console.error("[api/waitlist] Supabase error", {
+ code: error.code,
+ status: error.status,
+ });
@@
- console.error("[api/waitlist] Unexpected error:", err);
+ console.error("[api/waitlist] Unexpected error", {
+ name: err instanceof Error ? err.name : "UnknownError",
+ });Also applies to: 52-52 🤖 Prompt for AI Agents |
||
| { | ||
| error: "Waitlist is temporarily unavailable. Please try again later.", | ||
| }, | ||
| { status: 503 } | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json({ ok: true }, { status: 201 }); | ||
| } catch (err) { | ||
| console.error("[api/waitlist] Unexpected error:", err); | ||
| return NextResponse.json( | ||
| { error: "Something went wrong. Please try again later." }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return 400 for malformed/non-object request bodies.
If JSON parsing fails or body is not an object, the handler falls into the catch block and returns 500. That should be a 400 client error.
🔧 Proposed fix
export async function POST(request: Request) { try { - const body = (await request.json()) as WaitlistPayload; + let body: WaitlistPayload; + try { + const parsed = await request.json(); + if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { + return NextResponse.json( + { error: "Invalid request body." }, + { status: 400 } + ); + } + body = parsed as WaitlistPayload; + } catch { + return NextResponse.json( + { error: "Invalid JSON body." }, + { status: 400 } + ); + }Also applies to: 51-56
🤖 Prompt for AI Agents