Route waitlist form through API with Resend email notification#7
Conversation
Submissions now go through /api/waitlist which inserts into Supabase and sends a notification email via Resend. Email failure is non-blocking so signups are never lost. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Summary of ChangesHello @kushal238, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the waitlist submission flow by introducing a dedicated API endpoint. This change centralizes form data handling, improves data validation, and integrates a reliable email notification system using Resend, all while ensuring that the core functionality of adding users to the waitlist remains robust even if email notifications encounter issues. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully refactors the waitlist form submission to use a new API endpoint. The API handles data validation, insertion into Supabase, and sends an email notification via Resend. The changes are well-structured. I've provided a few suggestions to improve security and performance on the server-side, such as using the Supabase service role key and moving expensive initializations out of the request handler. I've also suggested a minor improvement for code readability.
| const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; | ||
| const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY; | ||
|
|
||
| if (!supabaseUrl || !supabaseAnonKey) { | ||
| return NextResponse.json( | ||
| { error: "Server misconfiguration" }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
|
|
||
| const supabase = createClient(supabaseUrl, supabaseAnonKey); |
There was a problem hiding this comment.
For server-side operations, it's a security best practice to use the Supabase service role key instead of the public anonymous key. The service role key bypasses Row Level Security (RLS) and is meant for trusted server environments. Using the public anon key subjects this endpoint to the same RLS policies as a client-side request.
Please use the service role key stored in a private environment variable (e.g., SUPABASE_SERVICE_KEY, without the NEXT_PUBLIC_ prefix).
| const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; | |
| const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY; | |
| if (!supabaseUrl || !supabaseAnonKey) { | |
| return NextResponse.json( | |
| { error: "Server misconfiguration" }, | |
| { status: 500 }, | |
| ); | |
| } | |
| const supabase = createClient(supabaseUrl, supabaseAnonKey); | |
| const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; | |
| const supabaseServiceKey = process.env.SUPABASE_SERVICE_KEY; | |
| if (!supabaseUrl || !supabaseServiceKey) { | |
| return NextResponse.json( | |
| { error: "Server misconfiguration" }, | |
| { status: 500 }, | |
| ); | |
| } | |
| const supabase = createClient(supabaseUrl, supabaseServiceKey); |
| const callingCodes = customList( | ||
| "countryCode", | ||
| "+{countryCallingCode}", | ||
| ) as Record<string, string>; |
There was a problem hiding this comment.
To improve performance, objects that can be reused across requests should be initialized only once at the module level, instead of inside the request handler.
- The
callingCodesobject can be created once at the module scope. - The
resendclient (initialized on line 95) can also be initialized once at the module scope.
This avoids redundant computation and object creation on each API call.
Example:
// At module scope
const callingCodes = customList("countryCode", "+{countryCallingCode}") as Record<string, string>;
const resend = process.env.RESEND_API_KEY ? new Resend(process.env.RESEND_API_KEY) : null;
export async function POST(request: Request) {
// ... remove initializations from here and use the module-scoped variables
}| text: [ | ||
| `New waitlist signup`, | ||
| ``, | ||
| `Name: ${values.name}`, | ||
| `Email: ${values.email}`, | ||
| `Phone: ${fullPhoneNumber}`, | ||
| `User type: ${values.userType}${values.userTypeOther ? ` (${values.userTypeOther})` : ""}`, | ||
| `Features: ${values.features.join(", ")}${values.featuresOther ? ` (Other: ${values.featuresOther})` : ""}`, | ||
| `Source: ${values.source}${values.sourceOther ? ` (${values.sourceOther})` : ""}`, | ||
| ].join("\n"), |
There was a problem hiding this comment.
The construction of the email body can be simplified and made more readable by using a template literal instead of joining an array of strings.
text: `New waitlist signup
Name: ${values.name}
Email: ${values.email}
Phone: ${fullPhoneNumber}
User type: ${values.userType}${values.userTypeOther ? ` (${values.userTypeOther})` : ""}
Features: ${values.features.join(", ")}${values.featuresOther ? ` (Other: ${values.featuresOther})` : ""}
Source: ${values.source}${values.sourceOther ? ` (${values.sourceOther})` : ""}`,Address PR review: use SUPABASE_SERVICE_KEY instead of public anon key for server-side inserts, and move callingCodes map and Resend client to module scope to avoid re-creating per request. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request routes waitlist form submissions through an API endpoint (/api/waitlist) to insert data into Supabase and send notification emails via Resend, removing direct client-side Supabase integration. A critical security concern has been identified where server-side logs may inadvertently capture full error objects from external services, potentially exposing user PII such as email addresses. It is recommended to sanitize these logs to enhance data privacy. The implementation also includes form validation using Zod, error handling, and non-blocking email notifications.
| ].join("\n"), | ||
| }); | ||
| } catch (emailError) { | ||
| console.error("Failed to send notification email:", emailError); |
| if (!supabaseUrl || !supabaseServiceKey) { | ||
| return NextResponse.json( | ||
| { error: "Server misconfiguration" }, | ||
| { status: 500 }, | ||
| ); | ||
| } |
There was a problem hiding this comment.
high: It's good to check for supabaseUrl and supabaseServiceKey, but consider logging a more specific error message indicating which environment variable is missing. This will help in debugging server misconfigurations.
if (!supabaseUrl) {
console.error("NEXT_PUBLIC_SUPABASE_URL is missing");
return NextResponse.json(
{ error: "Server misconfiguration: NEXT_PUBLIC_SUPABASE_URL is missing" },
{ status: 500 },
);
}
if (!supabaseServiceKey) {
console.error("SUPABASE_SERVICE_KEY is missing");
return NextResponse.json(
{ error: "Server misconfiguration: SUPABASE_SERVICE_KEY is missing" },
{ status: 500 },
);
}| const data = await res.json().catch(() => null); | ||
| throw new Error(data?.error || "Request failed"); |
There was a problem hiding this comment.
high: The catch block uses .catch(() => null) which can mask errors. It's better to handle the error explicitly to avoid swallowing important information. Consider logging the error or providing a default error message.
const data = await res.json().catch((error) => {
console.error("Error parsing JSON response:", error);
return { error: "Failed to parse server response" }; // Provide a default error message
});
| ].join("\n"), | ||
| }); | ||
| } catch (emailError) { | ||
| console.error("Failed to send notification email:", emailError); |
There was a problem hiding this comment.
This line logs the full error object from Resend, which can inadvertently expose sensitive user information (PII) like email addresses to log management systems. It is crucial to sanitize logs by only capturing the error message or a generic failure notification to prevent PII leakage. Furthermore, while the email sending is non-blocking, consider implementing retry logic within this catch block to enhance the reliability of email notifications.
| console.error("Failed to send notification email:", emailError); | |
| console.error("Failed to send notification email:", emailError instanceof Error ? emailError.message : "Unknown error"); |
| }); | ||
|
|
||
| if (dbError) { | ||
| console.error("Supabase insert error:", dbError); |
There was a problem hiding this comment.
The application logs the full error object from Supabase when a database insertion fails. These error objects, particularly for unique constraint violations (e.g., duplicate email), often contain the sensitive data that caused the error, such as the user's email address. Logging this information exposes Personally Identifiable Information (PII) to anyone with access to the server logs or log management systems. It is recommended to log only non-sensitive information, such as the error message or error code.
| console.error("Supabase insert error:", dbError); | |
| console.error("Supabase insert error:", dbError.message); |
| // Hoist static objects to module scope to avoid re-creating per request | ||
| const callingCodes = customList( | ||
| "countryCode", | ||
| "+{countryCallingCode}", | ||
| ) as Record<string, string>; |
| const resend = process.env.RESEND_API_KEY | ||
| ? new Resend(process.env.RESEND_API_KEY) | ||
| : null; |
There was a problem hiding this comment.
medium: It's good to handle the case where RESEND_API_KEY is not defined, but consider adding a log message to indicate when the Resend client is not initialized. This can help with debugging in environments where the email functionality is expected to work.
| const resend = process.env.RESEND_API_KEY | |
| ? new Resend(process.env.RESEND_API_KEY) | |
| : null; | |
| const resend = process.env.RESEND_API_KEY | |
| ? new Resend(process.env.RESEND_API_KEY) | |
| : (console.warn("RESEND_API_KEY is not defined. Email notifications will not be sent."), null); |
| "pixelmatch": "^5.3.0", | ||
| "pngjs": "^7.0.0", | ||
| "postcss": "^8.5.6", | ||
| "tailwindcss": "^3.4.17", | ||
| "typescript": "^5.8.3", | ||
| "typescript-eslint": "^8.38.0", |
Submissions now go through /api/waitlist which inserts into Supabase and sends a notification email via Resend. Email failure is non-blocking so signups are never lost.