Client - change UI display only on login ou user preferences update
This commit is contained in:
parent
d207beb78f
commit
ee35f8760e
@ -57,7 +57,7 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
|||||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN,
|
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN,
|
||||||
window.localStorage.authToken
|
window.localStorage.authToken
|
||||||
)
|
)
|
||||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE, true)
|
||||||
}
|
}
|
||||||
// after logout in another tab
|
// after logout in another tab
|
||||||
if (
|
if (
|
||||||
@ -118,13 +118,16 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||||
context: ActionContext<IAuthUserState, IRootState>
|
context: ActionContext<IAuthUserState, IRootState>,
|
||||||
|
updateUI: boolean = false
|
||||||
): void {
|
): void {
|
||||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||||
authApi
|
authApi
|
||||||
.get('auth/profile')
|
.get('auth/profile')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data.status === 'success') {
|
if (res.data.status === 'success') {
|
||||||
|
const profileNotLoaded =
|
||||||
|
context.getters[AUTH_USER_STORE.GETTERS.IS_PROFILE_NOT_LOADED]
|
||||||
context.commit(
|
context.commit(
|
||||||
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_USER_PROFILE,
|
||||||
res.data.data
|
res.data.data
|
||||||
@ -133,16 +136,18 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
|||||||
// refresh privacy policy
|
// refresh privacy policy
|
||||||
context.dispatch(ROOT_STORE.ACTIONS.GET_APPLICATION_PRIVACY_POLICY)
|
context.dispatch(ROOT_STORE.ACTIONS.GET_APPLICATION_PRIVACY_POLICY)
|
||||||
}
|
}
|
||||||
if (res.data.data.language) {
|
if (profileNotLoaded || updateUI) {
|
||||||
context.dispatch(
|
if (res.data.data.language) {
|
||||||
ROOT_STORE.ACTIONS.UPDATE_APPLICATION_LANGUAGE,
|
context.dispatch(
|
||||||
res.data.data.language
|
ROOT_STORE.ACTIONS.UPDATE_APPLICATION_LANGUAGE,
|
||||||
|
res.data.data.language
|
||||||
|
)
|
||||||
|
}
|
||||||
|
context.commit(
|
||||||
|
ROOT_STORE.MUTATIONS.UPDATE_DARK_MODE,
|
||||||
|
res.data.data.use_dark_mode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
context.commit(
|
|
||||||
ROOT_STORE.MUTATIONS.UPDATE_DARK_MODE,
|
|
||||||
res.data.data.use_dark_mode
|
|
||||||
)
|
|
||||||
context.dispatch(SPORTS_STORE.ACTIONS.GET_SPORTS)
|
context.dispatch(SPORTS_STORE.ACTIONS.GET_SPORTS)
|
||||||
} else {
|
} else {
|
||||||
handleError(context, null)
|
handleError(context, null)
|
||||||
@ -174,7 +179,7 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
|||||||
window.localStorage.setItem('authToken', token)
|
window.localStorage.setItem('authToken', token)
|
||||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||||
context
|
context
|
||||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE, true)
|
||||||
.then(() =>
|
.then(() =>
|
||||||
router.push(
|
router.push(
|
||||||
typeof data.redirectUrl === 'string' ? data.redirectUrl : '/'
|
typeof data.redirectUrl === 'string' ? data.redirectUrl : '/'
|
||||||
|
@ -26,6 +26,7 @@ export enum AuthUserGetters {
|
|||||||
AUTH_USER_PROFILE = 'AUTH_USER_PROFILE',
|
AUTH_USER_PROFILE = 'AUTH_USER_PROFILE',
|
||||||
IS_ADMIN = 'IS_ADMIN',
|
IS_ADMIN = 'IS_ADMIN',
|
||||||
IS_AUTHENTICATED = 'IS_AUTHENTICATED',
|
IS_AUTHENTICATED = 'IS_AUTHENTICATED',
|
||||||
|
IS_PROFILE_NOT_LOADED = 'IS_PROFILE_NOT_LOADED',
|
||||||
IS_SUCCESS = 'IS_SUCCESS',
|
IS_SUCCESS = 'IS_SUCCESS',
|
||||||
IS_REGISTRATION_SUCCESS = 'IS_REGISTRATION_SUCCESS',
|
IS_REGISTRATION_SUCCESS = 'IS_REGISTRATION_SUCCESS',
|
||||||
USER_LOADING = 'USER_LOADING',
|
USER_LOADING = 'USER_LOADING',
|
||||||
|
@ -35,4 +35,7 @@ export const getters: GetterTree<IAuthUserState, IRootState> &
|
|||||||
[AUTH_USER_STORE.GETTERS.USER_LOADING]: (state: IAuthUserState) => {
|
[AUTH_USER_STORE.GETTERS.USER_LOADING]: (state: IAuthUserState) => {
|
||||||
return state.loading
|
return state.loading
|
||||||
},
|
},
|
||||||
|
[AUTH_USER_STORE.GETTERS.IS_PROFILE_NOT_LOADED]: (state: IAuthUserState) => {
|
||||||
|
return state.authUserProfile.username === undefined
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,8 @@ export interface IAuthUserActions {
|
|||||||
): void
|
): void
|
||||||
|
|
||||||
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||||
context: ActionContext<IAuthUserState, IRootState>
|
context: ActionContext<IAuthUserState, IRootState>,
|
||||||
|
updateUI: boolean
|
||||||
): void
|
): void
|
||||||
|
|
||||||
[AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
[AUTH_USER_STORE.ACTIONS.LOGIN_OR_REGISTER](
|
||||||
@ -142,6 +143,10 @@ export interface IAuthUserGetters {
|
|||||||
|
|
||||||
[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED](state: IAuthUserState): boolean
|
[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED](state: IAuthUserState): boolean
|
||||||
|
|
||||||
|
[AUTH_USER_STORE.GETTERS.IS_PROFILE_NOT_LOADED](
|
||||||
|
state: IAuthUserState
|
||||||
|
): boolean
|
||||||
|
|
||||||
[AUTH_USER_STORE.GETTERS.IS_REGISTRATION_SUCCESS](
|
[AUTH_USER_STORE.GETTERS.IS_REGISTRATION_SUCCESS](
|
||||||
state: IAuthUserState
|
state: IAuthUserState
|
||||||
): boolean
|
): boolean
|
||||||
|
Loading…
Reference in New Issue
Block a user