Created
September 10, 2019 20:52
-
-
Save naillizard/16e4e99962099090a9cfb4e6474f166c to your computer and use it in GitHub Desktop.
Sapper recaptcha siteverify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
export async function post(req, res, next) { | |
res.setHeader('Content-Type', 'application/json') | |
let response; | |
const secret = '<YOUR-SECRET-KEY>' | |
const { captchaToken } = req.body | |
const captchaResponse = await axios.post(`https://www.google.com/recaptcha/api/siteverify?secret=${secret}&response=${captchaToken}`) | |
const { success, action, score } = captchaResponse.data | |
if (success && action === '<ACTION>' && score >= 0.7) { | |
response = captchaResponse.data | |
} | |
return await res.end(JSON.stringify(response)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment