Manually initialize ReCaptcha Module with dynamic siteKey?
nperegrine opened this issue · 4 comments
Hi, thanks for this awesome library,
I have been using this package for a while with no issues.
Recently I developed a project where I need the ability to:
1.) Manually initialize ReCaptcha siteKey
Basically, I want to be able to change the ReCaptcha site key after running "npm run build" using a dynamic Google ReCaptcha siteKey based on/provided by the client own deployment of the app (ps: they cannot edit nuxt.config.js and rebuild project that's why I really need this solution).
A similar option is currently available with @nuxtjs/gtm
Where we can do the following:
nuxt.config.js
export default { modules: [ '@nuxtjs/gtm' ], plugins: [ '~/plugins/gtm' ] }
plugins/gtm.js:
export default function({ $gtm, route }) { $gtm.init('GTM-XXXXXXX') }
Could a similar option like this please be added to this module? Seems like it shouldn't be very complicated to add!!!
Please any guidance or assistance on how to achieve this with this module would be greatly appreciated.
Thanks so much in advance!
Actually you can update the plugin siteKey by editing plugin's property itself, see #70 (comment)
Take into account that if you're updating the key to a different recaptcha version (from 2 to 3, or viceversa), you'll need to trigger a component re render. Let me know if that works for you.
@Marcosaurios thanks for your time and response,
Actually, I am using version 3 Invisible ReCaptcha!
Is it currently possible to accomplish this behavior in #70 (comment) and perform the initialization inside <script></script> section of components ?
like for example:
this.$recaptcha.init(this.$nuxt.$recaptcha.siteKey)
?
or
this.$recaptcha.init(this.$config.recaptcha_sitekey)
? using the new nuxt runtime config ?
Sure, I think so. I don't think you will need to init again the plugin, just update the variable this.$recaptcha.siteKey = "new value"
and check in Inspect > Network the network request with the updated siteKey.
@Marcosaurios thanks for your time and response,
Actually, I am using version 3 Invisible ReCaptcha!
Is it currently possible to accomplish this behavior in #70 (comment) and perform the initialization inside <script></script> section of components ?
like for example:
this.$recaptcha.init(this.$nuxt.$recaptcha.siteKey)
?or
this.$recaptcha.init(this.$config.recaptcha_sitekey)
? using the new nuxt runtime config ?
This is something we are needing aswel. For v3 you cannot update the sitekey dynamically after build. Is this functionality likely to be implemented at all?