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

feat: runtime config #70

Merged
merged 7 commits into from
Feb 2, 2021
Merged

Conversation

bason8800
Copy link
Contributor

No description provided.

@Marcosaurios
Copy link

I was thinking about opening a new PR solving this issue, updating the plugin configuration in runtime. Thanks @bason8800 for the approach, I hope it gets merged!

@MrCode1997
Copy link

Hope, this will be merged soon!

@Marcosaurios
Copy link

To solve the problem with using multiple instances or versions of Google Recaptcha on the same page,I just discovered that if you need to change the plugin settings in runtime, you can do it updating plugin's object directly via window.$nuxt.$recaptcha.version = 3 (in nuxt) or this.$recaptcha in vue.

The point is if you update the plugin's version and siteKey you will need to force a render on the <recaptcha /> plugin's component. I solved it adding the attribute :key (see VUE docs :key attribute) to the recaptcha component, and passing it the new updated value. Every time the :key property updates, the component will be rendered again. For example:

<recaptcha :key="this.$nuxt.$recaptcha.siteKey"
   @error="captchaV2Error"
   @success="captchaV2Success"
   @expired="captchaV2Expired"
 />

By this way, each time you update plugin's version and siteKey (in this order), the component will render again with the updated values from the plugin, so that you can use the same recaptcha component for testing V3 and V2 version.

I hope it helps as I have been struggling with this for almost a week.
@joelfloressottile @belgacea

@atinux
Copy link
Member

atinux commented Jan 30, 2021

Thank you for this great PT @bason8800

Do you mind adding a note into the README to show how to use the publicRuntimeConfig too?

@bason8800
Copy link
Contributor Author

@atinux done

Copy link
Member

farnabaz commented Feb 1, 2021

Thank you for the contribution @bason8800
I don't see the reason behind this changes. What is the difference between these two?

Proposed by this PR:

export default {
  publicRuntimeConfig: {
     recaptcha: {
       siteKey: process.env.RECAPTCHA_SITE_KEY
    }
  }
}

Current state:

export default {
   recaptcha: {
      siteKey: process.env.RECAPTCHA_SITE_KEY
    }
}

@MrCode1997
Copy link

MrCode1997 commented Feb 1, 2021

Hi @farnabaz , with the @bason8800 change, we can use publicRuntimeConfig, to change the env var for sitekey without rebuild all project, but just launching the "npm start" command, we can have the var updated.

The normal way, compile the env var in a bundle that nuxt use to start, with publicRuntimeConfig the var are read runtime with the start of the project.

Thx

lib/plugin.js Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@atinux
Copy link
Member

atinux commented Feb 1, 2021

Changes looks good, I added two small code suggestions

bason8800 and others added 2 commits February 1, 2021 21:34
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
@farnabaz
Copy link
Member

farnabaz commented Feb 2, 2021

@bason8800 Do you mind to resolve conflicts? (I don't have write permission of your repo)

@farnabaz farnabaz changed the title Runtime config feat: runtime config Feb 2, 2021
@farnabaz farnabaz merged commit e090317 into nuxt-community:master Feb 2, 2021
@farnabaz
Copy link
Member

farnabaz commented Feb 2, 2021

Thank you @bason8800

@farnabaz farnabaz mentioned this pull request Feb 2, 2021
Merged
mvrlin added a commit that referenced this pull request Feb 3, 2021
* Use PascalCase for component registration

This allows both `<Recaptcha>` and `<recaptcha>` to be used in templates.

Components that are registered in PascalCase can be used in templates with either PascalCase or kebab-case, whereas components registered in kebab-case can only be referenced in kebab-case. Some projects prefer to use PascalCase for component tags, so it's better for this plugin to make both options available.

See https://vuejs.org/v2/guide/components-registration.html#Name-Casing

* update plugin.js for global use

* Moved script element error callback to within promise so that the error can be caught further up the stack

* Reset ready state after error

* docs: remove david badge

* docs: add usage (#74)

Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>

* feat(multi-widget): render and verify multiple v2 widgets (#75)

* feat(language): enable google auto detection (#72)

Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>

* fix: describe error within execute() (#40)

Co-authored-by: Abdelhak Akermi <abdelhak@akermi.me>

* feat: runtime config (#70)

Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Nikolay Baskov <baskov@adv.ru>

* fix: remove badge on destroy (#76)

* Apply suggestions from code review

Co-authored-by: Simon Garner <simon.garner@madscience.co.nz>
Co-authored-by: mvrlin <mvrlin@pm.me>
Co-authored-by: lat1992 <lat1992@users.noreply.github.com>
Co-authored-by: Owen Andrews <owen@owenandre.ws>
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
Co-authored-by: Red Bayoub <40964509+redbayoub@users.noreply.github.com>
Co-authored-by: Abdelhak Akermi <abdelhak.akermi@gmail.com>
Co-authored-by: Abdelhak Akermi <abdelhak@akermi.me>
Co-authored-by: bason8800 <41577602+bason8800@users.noreply.github.com>
Co-authored-by: Nikolay Baskov <baskov@adv.ru>
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

Successfully merging this pull request may close these issues.

5 participants