duplicate namespace auth/ for the namespaced module auth

一笑奈何 提交于 2020-01-23 04:09:37

问题


I've been getting this error after installing nuxtjs module. I have tried every trick in the book to fix it, but seems like nothing is working.Added more information.

[vuex] duplicate namespace auth/ for the namespaced module auth

I've been frustrated with it.

auth: {
    plugins: [{ src: '~/plugins/axios', ssr: true }, '~/plugins/auth.js'],
    vuex: {
      namespace: 'auth'
    },
    strategies: {
      local: {
        endpoints: {
          login: {
            url: "login",
            method: "post",
            propertyName: "meta.token"
          },
          user: {
            url: "me",
            method: "get",
            propertyName: false
          },
          logout: {
            url: "logout",
            method: "post"
          },
          redirect: {
            login: "login",
            logout: "/",
            home: "/",
            callback: "/"
          },
          watchLoggedIn: true,
          rewriteRedirects: true
        }
      }
    }
  },

Plugins

plugins: [
    { src: "~/plugins/Maps.js", ssr: false },
    { src: "~/plugins/Typed.js", ssr: false },
    { src: "~/plugins/Animate.js", ssr: false },
    { src: "~/plugins/Counter.js", ssr: false },
    { src: "~plugins/Vimeo.js", ssr: false },
    "~plugins/mixins/user.js",
    "~plugins/mixins/validation.js",
  ],

auth.js <<---- Store

export const getters = {
    authenticated(state) {
        return state.loggedIn;
    },
    user(state) {
        return state.user;
    }
};

export const state = () => ({
    busy: false,
    loggedIn: false,
    strategy: "local",
    user: false
});

Following is the code, i currently have. If you need to see any other file, feel free to let me know.

https://www.youtube.com/watch?v=FojAfwueTLc


回答1:


Faced the same issue today after an update. To resolve:

Move the auth.js logic to index.js and delete auth.js.

index.js:

export const getters = {
    authenticated(state) {
      return state.auth.loggedIn
    },

    user(state) {
      return state.auth.user
    }
  }

If you are using a user.js mixin revise it as follows:

import Vue from 'vue'
import {mapGetters} from 'vuex'

    const User = {
        install(Vue, options) {
            Vue.mixin({
                computed: {
                    ...mapGetters({
                        user: 'user',
                        authenticated: 'authenticated'
                    })
                }
            })
        }
    };

    Vue.use(User);



回答2:


You probably have a file inside your store folder called "auth.js" and you did not explicitly set vuex.namespace option in your nuxt.config.js file.

From the documentation:

every .js file inside the store directory is transformed as a namespaced module (index being the root module).

So that means, "auth" becomes a namespace automatically.

The issue is "auth" is also the default Vuex store namespace for keeping state because "vuex.namespace" option in your nuxt.config.js file is "auth" by default if none is set explicitly. That is where the duplicate comes.

To solve this, change your store/auth.js to something different like store/authentication.js or change your vuex.namespace option in your nuxt.config.js file to something other than "auth" or else it will be used as default.



来源:https://stackoverflow.com/questions/59338642/duplicate-namespace-auth-for-the-namespaced-module-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!