Skip to content

Commit

Permalink
Merge pull request #72 from celestiaorg/hotfix/fix-recaptcha-env
Browse files Browse the repository at this point in the history
Fix recaptcha env usage
  • Loading branch information
sysrex authored Jan 29, 2025
2 parents 01d2209 + 83576be commit 3b7075c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
4 changes: 3 additions & 1 deletion src/components/Newsletter/Newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Newsletter = () => {
const [isFocused, setIsFocused] = useState(false);
const reCaptchaRef = useRef(null);

const siteKey = process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY;
const siteKey = process.env.RECAPTCHA_SITE_KEY;

const handleChange = (e) => {
setEmail(e.target.value);
Expand All @@ -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 3b7075c

Please sign in to comment.