import { Action , Module , Mutation , VuexModule } from 'vuex-module-decorators' ; import { UserProfile , editUserProfile , getUserProfile , initAuthentication , isAuthenticated , login , } from '@/authentication' ; @ Module ( { namespaced : true } ) export default class AuthModule extends VuexModule { private isAuth = false ; private userProfile : UserProfile = { } ; @ Action ( { commit : 'setAuth' } ) async init ( ) { await initAuthentication ( ) ; const isAuth = isAuthenticated ( ) ; if ( isAuth ) { await this . context . dispatch ( 'loadUserProfile' ) ; } return isAuth ; } @ Action ( { commit : 'setAuth' } ) async login ( ) { const isSuccessful = await login ( ) ; if ( isSuccessful ) { await this . context . dispatch ( 'loadUserProfile' ) ; } return isSuccessful ; } @ Action ( { commit : 'setAuth' } ) logout ( ) { this . context . commit ( 'setUserProfile' , { } ) ; return false ; } @ Action async editProfile ( ) { return await editUserProfile ( ) ; } @ Action ( { commit : 'setUserProfile' } ) async loadUserProfile ( ) { return await getUserProfile ( ) ; } @ Mutation private setAuth ( value ) { this . isAuth = value ; } @ Mutation private setUserProfile ( value ) { this . userProfile = value ; } }