Open Hamidrezana opened 4 years ago
You can try:
// nuxt.config.ts
auth: {
vuex: false
}
@DenisNikonov This works but is lose accessing user info with $auth.
There is no way on solving this issue ?
Look, I'm not saying that this is pretty, but will solve the issue. Thing is, I don't know what is nuxt/authjs doing that causes this. The workaround I've found to not disable vuex and still mantaining full functionality is to use dynamic stores.
So, you create the store within the declaration of the store's class and keep everything else as it is shown in docs example:
import Vuex from 'vuex'
import { Module, VuexModule, Mutation } from 'vuex-module-decorators'
interface RootState {}
const store = new Vuex.Store<RootState>({
actions: {
nuxtServerInit: () => {}
}
});
@Module({
stateFactory: true,
name: "exams",
dynamic: true,
namespaced: true,
store
})
export default class ExamsStore extends VuexModule {
public _exam: any = null;
private _activeTemplate: any = null;
@Mutation
setExam (exam: any) {
this._exam = exam
}
@Mutation
removeExam () {
this._exam = null
}
get exam () {
return this._exam;
}
}
Issue is still open, any news ? I have the same issue
I have the same issue.
I used this solution in [nuxtjs with Typescript documents].
In store section, they described how to using axios module in store module.
Created plug-in and util files, and using axios from created util file.
So, I little modified these.
import { Plugin } from '@nuxt/types'
import { initializeAuth } from '~/utils/auth'
const authAccessor: Plugin = ({ $auth }) => {
initializeAuth($auth);
};
export default authAccessor;
~/plugins/auth.ts
// define type any. Auth-module has not defined type.
let $auth: any | null = null;
export function initializeAuth(auth: any) {
$axios = auth;
}
export { $auth }
~/utils/auth.ts
and insert plug-in, not nuxt.config.ts -> plugins, please do nuxt.config.ts -> auth -> plug-ins.
...
const config: NuxtConfig = {
...
auth: {
...
plugins: [~/plugins/auth.ts],
...
},
};
...
nuxt.config.ts
You can use auth module :
import { $auth } from '~/utils/auth';
export default class [MODULE_NAME] extends VuexModule {
...
}
~/store/[something].ts
I am using nuxtjs with typescript and use vuex-module-decorators. but I get error when add
@nuxtjs/auth
to my project.This error happen when call Action.
When
@nuxtjs/auth
from modules it's ok.store/index.ts
utils/store-accessor