Coder Social home page Coder Social logo

Using with Nuxt3 about vue-recaptcha-v3 HOT 13 OPEN

auritylab avatar auritylab commented on July 20, 2024 13
Using with Nuxt3

from vue-recaptcha-v3.

Comments (13)

duongxinh2003 avatar duongxinh2003 commented on July 20, 2024 3

I resolved this issue:
First, in template html here is my code:

<template>
<v-form @submit.prevent="submitForm">
  <v-text-field
                      class="mb-3"
                      label="Username"
                      prepend-icon="mdi-account"
                      variant="outlined"
                      v-model="username.value.value"
                      :error-messages="username.errorMessage.value"
                  ></v-text-field>
  <v-text-field
                      label="Password"
                      prepend-icon="mdi-lock"
                      variant="outlined"
                      :type="showPassword ? 'text':'password'"
                      :append-inner-icon="showPassword ? 'mdi-eye':'mdi-eye-off'"
                      @click:append-inner="showPassword =! showPassword"
                      v-model="password.value.value"
                      :error-messages="password.errorMessage.value"
                  ></v-text-field>
<v-btn
                        type="submit"
                        class="w-100 g-recaptcha"
                        data-sitekey="reCAPTCHA_site_key"
                        data-callback='onSubmit'
                        data-action='submit'
                    >
                      Login
                    </v-btn>
</v-form>
</template>

Script:

<script lang="ts" setup>
import {useField, useForm} from 'vee-validate';
import { VueReCaptcha, useReCaptcha } from 'vue-recaptcha-v3'
...

const { vueApp } = useNuxtApp();
vueApp.use(VueReCaptcha, {
  siteKey: 'key-site',
  loaderOptions: {
    renderParameters: {
      hl: 'en'
    }
  }
})
const recaptchaInstance = useReCaptcha();
const submitForm = handleSubmit(async values => {
  await recaptchaInstance?.recaptchaLoaded();
  const token = await recaptchaInstance?.executeRecaptcha('submit')
  values.googleReCaptchaToken = token
  console.log('Google recaptChaToken: ', values.googleReCaptchaToken);
});

And here is my result:
Screen Shot 2023-03-02 at 6 51 24 PM

from vue-recaptcha-v3.

morteza-mortezai avatar morteza-mortezai commented on July 20, 2024 2

Hi,
I did as above for nuxt 3 .
but I get this error
image
do you know why is that?

from vue-recaptcha-v3.

lperez22 avatar lperez22 commented on July 20, 2024 2

I have run into this issue before when trying to initialize it in a method that is asynchronous, what I ended up doing was making a composable file

import { VueReCaptcha, useReCaptcha } from 'vue-recaptcha-v3';

export function useVueRecaptcha(pubicKey) {
  const { vueApp } = useNuxtApp();
  vueApp.use(VueReCaptcha, {
    siteKey: pubicKey,
    loaderOptions: { autoHideBadge: true },
  });
  const { executeRecaptcha, recaptchaLoaded } = useReCaptcha();
  return async (action) => {
    await recaptchaLoaded();
    return await executeRecaptcha(action);
  };
}

And then on mounted I call the composable and I pass in my siteKey to initialize the package and on submit I call recaptcha

  data() {
    return {
      recaptcha: null,
    }
  }
  mounted() {
    this.recaptcha = useVueRecaptcha(this.recaptchaKey);
  },
  methods: {
    async onSubmit() {
      const recaptchaToken = await this.recaptcha('login');
  }
}

from vue-recaptcha-v3.

ezioadf2 avatar ezioadf2 commented on July 20, 2024

ty man u saved my time♥

from vue-recaptcha-v3.

morteza-mortezai avatar morteza-mortezai commented on July 20, 2024

I've tried that , but it didn't work again .
and the same error is shown

from vue-recaptcha-v3.

KareemDa avatar KareemDa commented on July 20, 2024

For those who are facing the error

Hi,
I did as above for nuxt 3 .
but I get this error
image
do you know why is that?

Try this instead:

ort const useVueRecaptcha = async () => {
  const { vueApp } = useNuxtApp()
  vueApp.use(VueReCaptcha, {
    siteKey: '6Lc1dLcjAAAAAJv-IVAfPpKH3DG42HIOGbHapY-Y',
    loaderOptions: {
      autoHideBadge: true,
    },
  })

  const recaptchaInstance = useReCaptcha()

  await recaptchaInstance?.recaptchaLoaded()
  return await recaptchaInstance?.executeRecaptcha('login')
}

from vue-recaptcha-v3.

duongxinh2003 avatar duongxinh2003 commented on July 20, 2024

Hi, I did as above for nuxt 3 . but I get this error image do you know why is that?

I have same problem

from vue-recaptcha-v3.

saturniesm avatar saturniesm commented on July 20, 2024

I resolved this issue: First, in template html here is my code:

<template>
<v-form @submit.prevent="submitForm">
  <v-text-field
                      class="mb-3"
                      label="Username"
                      prepend-icon="mdi-account"
                      variant="outlined"
                      v-model="username.value.value"
                      :error-messages="username.errorMessage.value"
                  ></v-text-field>
  <v-text-field
                      label="Password"
                      prepend-icon="mdi-lock"
                      variant="outlined"
                      :type="showPassword ? 'text':'password'"
                      :append-inner-icon="showPassword ? 'mdi-eye':'mdi-eye-off'"
                      @click:append-inner="showPassword =! showPassword"
                      v-model="password.value.value"
                      :error-messages="password.errorMessage.value"
                  ></v-text-field>
<v-btn
                        type="submit"
                        class="w-100 g-recaptcha"
                        data-sitekey="reCAPTCHA_site_key"
                        data-callback='onSubmit'
                        data-action='submit'
                    >
                      Login
                    </v-btn>
</v-form>
</template>

Script:

<script lang="ts" setup>
import {useField, useForm} from 'vee-validate';
import { VueReCaptcha, useReCaptcha } from 'vue-recaptcha-v3'
...

const { vueApp } = useNuxtApp();
vueApp.use(VueReCaptcha, {
  siteKey: 'key-site',
  loaderOptions: {
    renderParameters: {
      hl: 'en'
    }
  }
})
const recaptchaInstance = useReCaptcha();
const submitForm = handleSubmit(async values => {
  await recaptchaInstance?.recaptchaLoaded();
  const token = await recaptchaInstance?.executeRecaptcha('submit')
  values.googleReCaptchaToken = token
  console.log('Google recaptChaToken: ', values.googleReCaptchaToken);
});

And here is my result: Screen Shot 2023-03-02 at 6 51 24 PM

Hello, when i tried to use the usual button component, i get this error:
image
even tho i already change the data-sitekey="reCAPTCHA_site_key" to my site-key. does anyone knows why i get this error? thank you

from vue-recaptcha-v3.

danieldanielecki avatar danieldanielecki commented on July 20, 2024

For some reason, the same code didn't work in composable, but worked in component. no idea, but thanks for all the answers

from vue-recaptcha-v3.

hendisantika avatar hendisantika commented on July 20, 2024

Where We can find the reCAPTCHA V3 is working well?

Thanks

from vue-recaptcha-v3.

devkazuto avatar devkazuto commented on July 20, 2024

Where We can find the reCAPTCHA V3 is working well?

Thanks

Same Here

from vue-recaptcha-v3.

hendisantika avatar hendisantika commented on July 20, 2024

Maybe this article could help us --> https://dev.to/elquimeras/integrate-recaptcha-v3-on-nuxt3-app-1gma

from vue-recaptcha-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.