Skip to content
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

error executing getResponse function with version 2 invisible mode #133

Open
JuanDa90laq opened this issue Nov 28, 2024 · 0 comments
Open

Comments

@JuanDa90laq
Copy link

I am implementing the base example code that is shared in the documentation, at the moment of executing the getResponse method it fails me, when looking at the error it shows the following error:

Login error: TypeError: Cannot read properties of null (reading 'execute') at eval (recaptcha.js:76:1) at new Promise (<anonymous>) at ReCaptcha.getResponse (recaptcha.js:73:1)

Apparently it is not initializing correctly and that is why it tells me that execute does not exist.

Image

<template>
  <section class="index-page">
    <h2>Sign In</h2>

    <form @submit.prevent="onSubmit">
      <input
        autocomplete="true"
        placeholder="Email"
        type="email"
        v-model="email"
      >

      <input
        autocomplete="current-password"
        placeholder="Password"
        type="password"
        v-model="password"
      >

      <recaptcha
        @error="onError"
        @success="onSuccess"
        @expired="onExpired"
      />

      <button type="submit">Sign In</button>
      <nuxt-link :to="{ name: 'about' }">About</nuxt-link>
    </form>
  </section>
</template>

<script>
export default {
  data: () => ({
    email: '[email protected]',
    password: '123',
  }),

  methods: {
    onError (error) {
      console.log('Error happened:', error)
    },

    async onSubmit() {
      try {
        const token = await this.$recaptcha.getResponse()

        const response = await fetch('/api/check-token', {
          method: 'POST',
          body: JSON.stringify({
            token,
            email: this.email,
            password: this.password
          })
        }).then(res => res.json())

        console.log('Server Response: ', response)

        await this.$recaptcha.reset()
      } catch (error) {
        console.log('Login error:', error)
      }
    },

    onSuccess (token) {
      console.log('Succeeded:', token)
    },

    onExpired () {
      console.log('Expired')
    }
  },
}
</script>

This is the code I am using to obtain the token

and this is the configuration in nuxt.config

publicRuntimeConfig: {
    recaptcha: {
      /* reCAPTCHA options */
      hideBadge: true, // Hide badge element (v3 & v2 via size=invisible),
      size: 'invisible',
      siteKey: process.env.API_KEY_RECAPTCHA,
      version: 2
    }
  },

 

    // Modules: https://go.nuxtjs.dev/config-modules
    modules: [
     // https://nuxt.com/modules/gtm
    '@nuxtjs/gtm',
    // https://v8.i18n.nuxtjs.org/
    '@nuxtjs/i18n',
    // https://github.com/nuxt-community/dayjs-module
    '@nuxtjs/dayjs',
    // https://www.npmjs.com/package/cookie-universal-nuxt
    'cookie-universal-nuxt',
    // https://www.npmjs.com/package/@nuxtjs/recaptcha
    '@nuxtjs/recaptcha'
  ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant