-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot destructure property 'executeRecaptcha' #682
Comments
同样的问题,你的解决了吗 |
same issue |
Just installed the library, same issue here. I believe the problem is that executing |
same issue |
Same issue here, can confirm what @mcorraodab said, Anyone solved this? |
Solution : import { useReCaptcha } from 'vue-recaptcha-v3';
const reCaptcha = useReCaptcha();
const login = async () => {
await reCaptcha.recaptchaLoaded();
const token = await reCaptcha.executeRecaptcha('login');
console.log('token', token);
} |
Get this logging in SSR for that @cedroux injection "Symbol(VueReCaptchaInjectKey)" not found. |
Solution is based on this article @jackkitley mentioned it is occurring in SSR. This approach utilizes the onMounted, which is only called client side. // googleRecaptcha.composable.ts
import { type IReCaptchaComposition, useReCaptcha } from 'vue-recaptcha-v3'
export function useGoogleRecaptcha() {
const recaptchaInstance = ref<IReCaptchaComposition | undefined>()
onMounted(() => {
recaptchaInstance.value = useReCaptcha()
})
async function executeRecaptcha(action: string) {
if (!recaptchaInstance.value) {
throw new Error('Recaptcha instance is not available')
}
await recaptchaInstance.value.recaptchaLoaded()
return recaptchaInstance.value.executeRecaptcha(action)
}
return executeRecaptcha
} // nuxtRecaptchaPlugin.client.ts
import { VueReCaptcha } from 'vue-recaptcha-v3'
import type { IReCaptchaOptions } from 'vue-recaptcha-v3/dist/IReCaptchaOptions'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.hook('app:mounted', () => {
const options: IReCaptchaOptions = {
siteKey: {GOOGLE_RECAPTCHA_KEY},
loaderOptions: {
...
}
}
nuxtApp.vueApp.use(VueReCaptcha, options)
})
}) |
okay, but i disabled SSR, and the error again. |
I'm using the plugin in a Vue component but inside an Astro app. Not sure if that plays a role. Here's what I'm getting as an error:
The text was updated successfully, but these errors were encountered: