Client - remove all user data from store on logout

This commit is contained in:
Sam 2021-09-23 15:56:57 +02:00
parent 05d7fd53d9
commit 0cb4fae21e
7 changed files with 21 additions and 2 deletions

View File

@ -7,5 +7,6 @@ export enum StatisticsGetters {
}
export enum StatisticsMutations {
EMPTY_USER_STATS = 'EMPTY_USER_STATS',
UPDATE_USER_STATS = 'UPDATE_USER_STATS',
}

View File

@ -15,4 +15,7 @@ export const mutations: MutationTree<IStatisticsState> & TStatisticsMutations =
) {
state.statistics = statistics
},
[STATS_STORE.MUTATIONS.EMPTY_USER_STATS](state: IStatisticsState) {
state.statistics = {}
},
}

View File

@ -29,6 +29,7 @@ export type TStatisticsMutations<S = IStatisticsState> = {
state: S,
statistics: TStatisticsFromApi
): void
[STATS_STORE.MUTATIONS.EMPTY_USER_STATS](state: S): void
}
export type TStatisticsStoreModule<S = IStatisticsState> = Omit<

View File

@ -3,7 +3,13 @@ import { ActionContext, ActionTree } from 'vuex'
import authApi from '@/api/authApi'
import api from '@/api/defaultApi'
import router from '@/router'
import { ROOT_STORE, SPORTS_STORE, USER_STORE } from '@/store/constants'
import {
ROOT_STORE,
SPORTS_STORE,
STATS_STORE,
USER_STORE,
WORKOUTS_STORE,
} from '@/store/constants'
import { IRootState } from '@/store/modules/root/types'
import { IUserActions, IUserState } from '@/store/modules/user/types'
import { ILoginOrRegisterData } from '@/types/user'
@ -68,8 +74,10 @@ export const actions: ActionTree<IUserState, IRootState> & IUserActions = {
context: ActionContext<IUserState, IRootState>
): void {
localStorage.removeItem('authToken')
context.commit(USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN)
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
context.commit(STATS_STORE.MUTATIONS.EMPTY_USER_STATS)
context.commit(USER_STORE.MUTATIONS.CLEAR_AUTH_USER_TOKEN)
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUTS)
router.push('/login')
},
}

View File

@ -9,6 +9,7 @@ export enum WorkoutsGetters {
}
export enum WorkoutsMutations {
EMPTY_WORKOUTS = 'EMPTY_WORKOUTS',
SET_CALENDAR_WORKOUTS = 'SET_CALENDAR_WORKOUTS',
SET_USER_WORKOUTS = 'SET_USER_WORKOUTS',
}

View File

@ -20,4 +20,8 @@ export const mutations: MutationTree<IWorkoutsState> & TWorkoutsMutations = {
) {
state.user_workouts = workouts
},
[WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUTS](state: IWorkoutsState) {
state.calendar_workouts = []
state.user_workouts = []
},
}

View File

@ -39,6 +39,7 @@ export type TWorkoutsMutations<S = IWorkoutsState> = {
state: S,
workouts: IWorkout[]
): void
[WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUTS](state: S): void
}
export type TWorkoutsStoreModule<S = IWorkoutsState> = Omit<