Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ UPSTASH_REDIS_REST_TOKEN=

# Optional: WalletConnect project ID
# NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=

# Optional: Resend API key for feedback emails
# RESEND_API_KEY=
# RESEND_FROM_EMAIL=Certified <no-reply@certified.one>
73 changes: 73 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"next": "^16.1.6",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"resend": "^6.10.0",
"viem": "^2.46.3",
"wagmi": "^2.19.5"
},
Expand Down
72 changes: 72 additions & 0 deletions src/app/api/feedback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from "next/server";
import { Resend } from "resend";

if (!process.env.RESEND_API_KEY) {
console.warn("RESEND_API_KEY is not set — feedback emails will fail");
}

const resend = new Resend(process.env.RESEND_API_KEY);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add validation for missing API key.

If RESEND_API_KEY is not set, the Resend client initialization succeeds but email sending will fail at runtime with an unclear error. Consider failing fast with a clear message.

Proposed fix
+if (!process.env.RESEND_API_KEY) {
+  console.warn("RESEND_API_KEY is not set - feedback emails will fail");
+}
+
 const resend = new Resend(process.env.RESEND_API_KEY);

Or alternatively, return a more helpful error in the handler if the key is missing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const resend = new Resend(process.env.RESEND_API_KEY);
if (!process.env.RESEND_API_KEY) {
console.warn("RESEND_API_KEY is not set - feedback emails will fail");
}
const resend = new Resend(process.env.RESEND_API_KEY);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/api/feedback/route.ts` at line 4, Resend client is initialized
unconditionally which hides missing API key errors; before constructing the
Resend instance (the const resend = new Resend(...) line) validate
process.env.RESEND_API_KEY and fail fast with a clear message or throw an error
(or alternatively check inside the request handler and return a helpful 4xx
error) so that the Resend class is not instantiated with an undefined key;
update the code around the Resend initialization (referencing the Resend symbol
and RESEND_API_KEY env var) to validate and handle the missing key explicitly.

const SUPPORT_EMAIL = "support@hypercerts.org";
const FROM_EMAIL = process.env.RESEND_FROM_EMAIL || "Certified <no-reply@certified.one>";

export async function POST(req: NextRequest) {
try {
// CSRF origin check
const origin = req.headers.get("origin");
const host = req.headers.get("host");
if (!origin || !host || !origin.includes(host.split(":")[0])) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const { message, email } = await req.json();

if (!message || typeof message !== "string" || !message.trim()) {
return NextResponse.json({ error: "Message is required" }, { status: 400 });
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return NextResponse.json({ error: "Invalid email address" }, { status: 400 });
}

// Send feedback to support
await resend.emails.send({
from: FROM_EMAIL,
to: SUPPORT_EMAIL,
subject: "New feedback for Certified.app",
text: [
"New feedback received:",
"",
message,
"",
email ? `Reply-to: ${email}` : "No email provided",
].join("\n"),
...(email ? { replyTo: email } : {}),
});

// Send confirmation to user if they provided an email
if (email) {
await resend.emails.send({
from: FROM_EMAIL,
to: email,
subject: "Thank you for your feedback to Certified.app",
text: [
"Thank you for sharing your feedback with us!",
"",
"We've received the following message:",
"",
`"${message}"`,
"",
"We appreciate your input and will review it carefully.",
"",
"Best regards,",
"The Certified Team",
].join("\n"),
});
}

return NextResponse.json({ success: true });
} catch (error) {
console.error("Feedback error:", error);
return NextResponse.json({ error: "Failed to send feedback" }, { status: 500 });
}
}
Loading