duplicate namespace auth/ for the namespaced module auth

Total
1
Shares

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


Solution

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);
Leave a Reply

Your email address will not be published. Required fields are marked *