Skip to content

Commit

Permalink
Added console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabros20 committed Jan 29, 2025
1 parent a2ca581 commit 83576be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/app/api/newsletter/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
import mailchimp from "@mailchimp/mailchimp_marketing";

// Validate required environment variables
const requiredEnvVars = ["MAILCHIMP_API_KEY", "MAILCHIMP_LIST_ID", "MAILCHIMP_SERVER_PREFIX"];
const requiredEnvVars = ["MAILCHIMP_API_KEY", "MAILCHIMP_LIST_ID", "MAILCHIMP_SERVER_PREFIX", "RECAPTCHA_SECRET_KEY"];
for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
console.error(`Missing required environment variable: ${envVar}`);
Expand All @@ -29,6 +29,11 @@ function isValidEmail(email) {
}

async function verifyRecaptcha(token) {
if (!process.env.RECAPTCHA_SECRET_KEY) {
console.error("Missing RECAPTCHA_SECRET_KEY");
return false;
}

try {
const response = await fetch("https://www.google.com/recaptcha/api/siteverify", {
method: "POST",
Expand All @@ -39,6 +44,11 @@ async function verifyRecaptcha(token) {
});

const data = await response.json();

if (!data.success) {
console.error("reCAPTCHA verification failed:", data["error-codes"]);
}

return data.success;
} catch (error) {
console.error("reCAPTCHA verification failed:", error);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Newsletter/Newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const Newsletter = () => {
const handleSubmit = async (e) => {
e.preventDefault();

console.log("Submitting with token:", token);

if (isSubmitting) return;
if (!email) {
setStatus("Error");
Expand Down

0 comments on commit 83576be

Please sign in to comment.