Simple example to integrate Google recaptcha v3 https://medium.com/@asmitak/google-recaptcha-v3-with-firebase-functions-a04657d893a9
Create a new firebase project to test this example. Docs
firebase init
- Select Functions and Hosting
- Select existing project you created
- Select Javascript
- Select 'N' for all overwrite questions
- Select Yes to install dependencies
- Select public as the hosting directory
- Select 'N' to single-page app
Once you host on firebase, your site will be live on https://.firebaseapp.com. You can register this URL for recaptcha as mentioned here and get the secret and site keys
export ORIGIN=https://<Firebase-app-id>.firebaseapp.com
export SECRET_KEY=<RECAPTCHA_SECRET_KEY
firebase functions:config:set recaptacha.key=$SECRET_KEY recaptcha.origin=$ORIGIN
You can confirm using
firebase functions:config:get
firebase deploy --only functions
You should get the function endpoint such as - "https://us-central1-..."
export SITE_KEY=<RECAPTCHA_SITE_KEY>
export API_ENDPOINT=<YOUR FUNCTION ENDPOINT FROM PREV STEP>
./scripts/env.sh
firebase deploy --only hosting
You site should be live on https://.firebaseapp.com. You can enter values in the fields and hit submit to see the score returned by Google recaptcha on the next page
Apart from manually testing on the firebase app online, you can run the puppeteer test included:
node test/test.js
Open the screenshot.png created by the test, and you should see a the score returned by recaptcha