0

I have a nuxt3 app, and i want to add recaptcha to the registration form.

Im using vue-recaptcha-v3 package, like this in plugins/google-recaptcha.ts:

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

export default defineNuxtPlugin((nuxtApp) => {
  const config = useRuntimeConfig();

  nuxtApp.vueApp.use(VueReCaptcha, {
    siteKey: config.public.recaptchaKey,
    loaderOptions: {
      autoHideBadge: false,
      explicitRenderParameters: {
        badge: 'bottomleft'
      }
    }
  });
});

The problem is that i want the plugin to load only on the registration page, nowhere else. Any way to do this?

hatja
  • 51
  • 6
  • This is probably not done at nuxt level but at plugin level. Check [this](https://stackoverflow.com/a/70419078/11258206) answer to a similar question. In particular `recaptcha.hideBadge()`. – learntheropes Jun 26 '23 at 15:20
  • that way the plugin would be still loaded. I guess the way is to include the native google script on the specific page, and not using the vue-recaptcha-v3 package. As a workaround for now i used this in the plugin. ` if (!authStore.isLoggedIn()) { nuxtApp.vueApp.use(VueReCaptcha... } ` Its important to say that this will only work if the page is reloaded after login/registration, otherwise plugins would not "refresh". – hatja Jun 26 '23 at 16:54

0 Answers0