DanSnow / vue-recaptcha

Google ReCAPTCHA component for Vue.js
http://dansnow.github.io/vue-recaptcha/
MIT License
860 stars 134 forks source link

get captcha token in TS file #1486

Open alireza0sfr opened 7 months ago

alireza0sfr commented 7 months ago

Describe the feature

Hello Thanks for the amazing effort that you have put in this package,

I have a custom api plugin and I want to send recaptcha tokens on any POST request automatically this is a sample code to demonstrate:

import { useChallengeV3 } from 'vue-recaptcha'

if(payload && ['POST', 'PUT', 'PATCH'].includes(options.method)) {
        const { execute } = useChallengeV3(actionType)
        payload.RT = await execute()

but I can't use useChallengeV3 outside of a setup function or .vue file because it's a composable, Is there any workarounds ?

DanSnow commented 7 months ago

Maybe try to wrap useChallengeV3 with runWithContext https://vuejs.org/api/application.html#app-runwithcontext