Posts

Showing posts from April, 2025

How to add reCAPTCHA validation to your MERN stack app

Image
Go to https://www.google.com/recaptcha/admin/create  to register a new site. Choose Challenge v2 from the reCAPTCHA type section Add localhost as the domain of your site. Do not include the port of your application, e.g. localhost:8080 etc. After registering the new site you will get your secret key and site. We will need the site key on the frontend and the secret key on the backend for verification. The process: User completes the I am not a robot challenge. On the successful completion of the challenge a reCAPTCHA Token is generated on the frontend and sent to the backend for verification. The Backend uses the SECRET_KEY and the reCAPTCHA Token to send a POST request to the following url: ·          `https://www.google.com/recaptcha/api/siteverify?secret= ${ process . env . RECAPTCHA_SECRET_KEY } &response= ${ recaptchaToken } ` If the response object’s success property is true then the verification is successful. Here is t...