Client - remove all user data from store on logout
This commit is contained in:
		@@ -7,5 +7,6 @@ export enum StatisticsGetters {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export enum StatisticsMutations {
 | 
			
		||||
  EMPTY_USER_STATS = 'EMPTY_USER_STATS',
 | 
			
		||||
  UPDATE_USER_STATS = 'UPDATE_USER_STATS',
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,4 +15,7 @@ export const mutations: MutationTree<IStatisticsState> & TStatisticsMutations =
 | 
			
		||||
    ) {
 | 
			
		||||
      state.statistics = statistics
 | 
			
		||||
    },
 | 
			
		||||
    [STATS_STORE.MUTATIONS.EMPTY_USER_STATS](state: IStatisticsState) {
 | 
			
		||||
      state.statistics = {}
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -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<
 | 
			
		||||
 
 | 
			
		||||
@@ -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')
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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',
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = []
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user