mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 09:32:45 +00:00
687b56f18e
[web] Reset recaptcha every time GitOrigin-RevId: 6db3571ad6dad3611c748a2d92dce47002a16a77
20 lines
536 B
TypeScript
20 lines
536 B
TypeScript
import { useRef } from 'react'
|
|
import ReCAPTCHA from 'react-google-recaptcha'
|
|
|
|
export const useRecaptcha = () => {
|
|
const ref = useRef<ReCAPTCHA | null>(null)
|
|
|
|
const getReCaptchaToken = async (): Promise<
|
|
ReturnType<ReCAPTCHA['executeAsync']>
|
|
> => {
|
|
if (!ref.current) {
|
|
return null
|
|
}
|
|
// Reset the reCAPTCHA before each submission.
|
|
// The reCAPTCHA token is meant to be used once per validation
|
|
ref.current.reset()
|
|
return await ref.current.executeAsync()
|
|
}
|
|
|
|
return { ref, getReCaptchaToken }
|
|
}
|