DanSnow / vue-recaptcha

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

[version 3.0.0-alpha6]: Error: useRecaptcha() is called without provider. #1628

Open Prixii opened 6 months ago

Prixii commented 6 months ago

Description

i'm tring to use Checkbox in vue3, but console is outputting: Error: useRecaptcha() is called without provider. i've tried to call useRecaptchaProvider() in App.vue and Login.vue, but it didn't work.

Minimal Reproducible Example

main.ts

import { createApp } from 'vue'
import App from './App.vue'

import router from './router'
import { VueRecaptchaPlugin } from 'vue-recaptcha'

const app = createApp(App)

app.use(router)
app.use(VueRecaptchaPlugin, {
  v2SiteKey: 'MY_KEY'
})

app.mount('#app')

login.vue

<template>
  <div class="login-container">
    <div>{{ response ? 'Verified' : 'Please click the checkbox' }}</div>
    <Checkbox :key="theme" v-model="response" :theme="theme" />
  </div>
</template>

<script lang="ts" setup>
import { Checkbox, useRecaptchaProvider } from 'vue-recaptcha'
import { ref } from 'vue'

useRecaptchaProvider()

const theme = ref<'light' | 'dark'>('light')
const response = ref()
</script>
<style lang="scss" scoped></style>

System info

context.mjs:8 Uncaught (in promise) Error: useRecaptcha() is called without provider. at useRecaptchaContext (context.mjs:8:11) at useAssertV2SiteKey (context.mjs:17:15) at useChallengeV2 (challenge-v2.mjs:12:19) at useComponentV2 (component-v2.mjs:5:83) at setup (Checkbox.vue:46:18) at callWithErrorHandling (runtime-core.esm-bundler.js:193:18) at setupStatefulComponent (runtime-core.esm-bundler.js:7606:25) at setupComponent (runtime-core.esm-bundler.js:7567:36) at mountComponent (runtime-core.esm-bundler.js:5894:7) at processComponent (runtime-core.esm-bundler.js:5860:9)

DanSnow commented 6 months ago

I tried to use a simple project created by create-vue with the provided code and can't reproduce this. Could you provide a reproducible example with the build config?

imzoloft commented 5 months ago

I had this issue using 3.0.0-alpha.2, switched to 3.0.0-alpha.6 and it worked fine.