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

Multiple vue.js app instance support #142

Open
Andrei-Pozolotin opened this issue Aug 12, 2019 · 2 comments
Open

Multiple vue.js app instance support #142

Andrei-Pozolotin opened this issue Aug 12, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Andrei-Pozolotin
Copy link

Andrei-Pozolotin commented Aug 12, 2019

  1. this approach:
    https://d0whc3r.github.io/vue-auth-plugin/installation.html#use-vue-router-and-vuex
const store = new Vuex.Store({ ... });
(Vue as any).store = store;
      if (!_this.Vue.store) {
526:        throw Error('[vue-auth-plugin] vuex is a required dependency if you want to use "vuex" as storage');
      }

vue-auth-plugin.umd.js:526 Uncaught Error: [vue-auth-plugin] vuex is a required dependency if you want to use "vuex" as storage
    at new StoreVuex (vue-auth-plugin.umd.js:526)
    at vue-auth-plugin.umd.js:650
    at Array.map (<anonymous>)
    at AuthStoreManager.setStores (vue-auth-plugin.umd.js:640)
    at new AuthStoreManager (vue-auth-plugin.umd.js:622)
    at new Auth (vue-auth-plugin.umd.js:1833)
    at Object.install (vue-auth-plugin.umd.js:1893)
    at Function.Vue.use (vue.js:5094)
    at vue-auth-plugin.umd.js:1910
    at vue-auth-plugin.umd.js:9
  1. prevents using multiple vue.js app instances:
    https://vuex.vuejs.org/guide/state.html
    when store is injected per-instance:
const app = new Vue({
  el: '#app',
  // provide the store using the "store" option.
  // this will inject the store instance to all child components.
  store,
  components: { Counter },
  template: `
    <div class="app">
      <counter></counter>
    </div>
  `
})
  1. instead, VueAuthPlugin should behave as store-attached plugin:
    https://vuex.vuejs.org/guide/plugins.html
const store = new Vuex.Store({
  // ...
  plugins: [VueAuthPlugin] // can be class or instance
})
@d0whc3r
Copy link
Owner

d0whc3r commented Aug 14, 2019

If you have a solution for this, could you make a pr?

@Andrei-Pozolotin
Copy link
Author

a solution could be a change to a lazy-init pattern:

  Object.defineProperties(Vue.prototype, {
    $auth: {
      get: function get() {
        if (!this.__auth__) {
          if (this.$http) { /* use user-provided axios */ } else { /* use default http provider */ }
          if (this.$store) { /* use user-provided vuex */ } else { /* ... */ }
          if (this.$router) { /* use user-provided vue-router */ } else { /* ... */ }
          this.__auth__ = new VueAuthCore(this.$http, this.$store, this.$router, options);
        }
        return this.__auth__
      }
    }
  });

@d0whc3r d0whc3r self-assigned this Nov 15, 2020
@d0whc3r d0whc3r added enhancement New feature or request help wanted Extra attention is needed labels Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants