I am using nuxtjs with typescript and use vuex-module-decorators. but I get error when add @nuxtjs/auth to my project.
ERR_STORE_NOT_PROVIDED: To use getModule(), either the module
should be decorated with store in decorator, i.e. @Module({store:
store}) or
store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)
This error happen when call Action.
When @nuxtjs/auth from modules it's ok.
store/index.ts
import { Store } from "vuex";
import { initializeStores } from "~/utils/store-accessor";
const initializer = (store: Store<any>) => initializeStores(store);
export const plugins = [initializer];
export * from "~/utils/store-accessor";
utils/store-accessor
/* eslint-disable import/no-mutable-exports */
import { Store } from "vuex";
import { getModule } from "vuex-module-decorators";
import { NuxtAxiosInstance } from "@nuxtjs/axios";
import Login from "~/store/Login";
import App from "~/store/App";
let $axios: NuxtAxiosInstance;
function initializeAxios(axiosInstance: NuxtAxiosInstance) {
$axios = axiosInstance;
}
let loginStore: Login, appStore: App;
function initializeStores(store: Store<any>): void {
loginStore = getModule(Login, store);
appStore = getModule(App, store);
}
export { initializeStores, initializeAxios, loginStore, appStore, $axios };
I also have the same issue here.
I see a solution posted here: https://stackoverflow.com/a/63416004
with vuex: false set in nuxt.config.js, I created a auth.ts file under the store folder:
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
interface payload {
key: string
value: any
}
@Module({
name: 'auth',
stateFactory: true,
namespaced: true,
})
export default class AuthStore extends VuexModule {
user: any = null
loggedIn: boolean = false
@Mutation
SET(payload: payload) {
if (payload.key === 'user') {
this.user = payload.value
} else if (payload.key === 'loggedIn') {
this.loggedIn = payload.value
}
}
}
It seems to be working so far. This is only a workaround.
Hello, is there any solution to use latest version of vuex-module-decorators and @nuxtjs/auth together?
Can you please post a repro? You can use this as a base: https://codesandbox.io/s/nuxt-auth-demo-45icg
Closing for inactivity. If this is still a problem for anyone, please file a new issue and include the auth module version number together with a repro or, ideally, some basic debugging to figure out where the problem lies.
Most helpful comment
Hello, is there any solution to use latest version of vuex-module-decorators and @nuxtjs/auth together?