Rock Mountain
  • Home
  • User Guide
    • Glass Web Components
    • Using reCAPTCHA
    • Publishing Source Code with Syntax Highlighting
  • Developer Guide
    • Getting Started
    • Adding NPM Packages
    • Database
      • Backing Up and Restoring Data
      • Database Schema
      • MongoDB Tips and Snippets
      • VS Code and the MongoDB Playground
    • Common Errors and Their Solutions
    • Developing Glass Web Components
    • DevOps
      • Build and Deployment Procedure
      • GitHub Conventions and Workflow
      • Merging Preview Into Main
    • File Structure
    • React Components
      • SiteLayout Component
      • Toggle Lazy Load Image Component
    • Update or Change the Fav Icon
    • References and Learning Resources
  • Icons
Powered by GitBook
On this page
  • Setup
  • References
  1. User Guide

Using reCAPTCHA

PreviousGlass Web ComponentsNextPublishing Source Code with Syntax Highlighting

Last updated 3 years ago

is a free service from Google that protects your site from spam and abuse. It uses advanced risk analysis techniques to tell humans and bots apart. Rock Mountain leverages the reCAPTCHA service to help protect your site. It is used with the Contact form, for example, so that a robot cannot attempt to spam you with multiple emails or impose an overly high cloud service fees.

Setup

Currently, you must register two new projects on reCAPTCHA and get the required keys: one project for Preview and Development environments, and one project for Production. Here's how...

Let's start by registering the project for Preview and Development environments. Navigate to the , fill in the required details as shown below, and click on submit.

Notice that, to the list of domains, we added only localhost (our local development environment), codyburleson.cloud (our Preview environment), and vercel.app (a dev environment for any other non-prod branch that gets deployed to Vercel). That’s because we should only be using these keys for development purposes. reCAPTCHA also performs a domain validation for the site it’s being executed on, so we will also need to create a separate set of keys for the Production environment.

After clicking submit, you should be able to see the public and secret keys.

Add the generated keys and values to your .env.local file and to your Preview and Development environments in Vercel. Use the following keys:

# Add the public site key here
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=

# Add the secret key here
RECAPTCHA_SECRET_KEY=

If everything is working properly, you should be able to test this setup by running npm run dev and then sending yourself a message using the form on the Contact page. Of course, this also presupposes that you have the Contact form properly configured to send email through the cloud service (currently only AWS SES has been integrated).

If the reCAPTCHA integration was successful you should see the reCAPTCHA badge at the bottom right corner of your browser on the Contact page. If a challenge is not being shown to you, it doesn't necessarily mean there is something wrong with the integration because reCAPTCHA only shows a challenge if you fail its behavior or cookie analysis. If you still want to see the challenge anyway, you can update the security preference to "Most secure" from the reCAPTCHA admin dashboard (shown below) and then open the browser tab or window in incognito mode.

Now you need to follow the same procedure to create another project in reCAPTCHA for Production and then add the respective environment variables and values to your Production environment in Vercel.

References

reCAPTCHA from Google
Integrating reCAPTCHA with Next.js
Sample Code for the Article Above on GitHub
reCAPTCHA
reCAPTCHA admin console