|
|
|
@ -25,7 +25,7 @@ function loadCurrentSession() {
|
|
|
|
|
const state: SessionInterface = {
|
|
|
|
|
sessions: [],
|
|
|
|
|
currentSession: loadCurrentSession() || undefined,
|
|
|
|
|
loading: false,
|
|
|
|
|
loading: false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mutations: MutationTree<SessionInterface> = {
|
|
|
|
@ -44,11 +44,11 @@ const mutations: MutationTree<SessionInterface> = {
|
|
|
|
|
state.loading = value;
|
|
|
|
|
},
|
|
|
|
|
updateSession(state, session: FG.Session) {
|
|
|
|
|
const index = state.sessions.findIndex((x) => x.token == session.token);
|
|
|
|
|
const index = state.sessions.findIndex(x => x.token == session.token);
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
state.sessions[index] = session;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
@ -65,7 +65,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
commit('setCurrentSession', response.data.session);
|
|
|
|
|
commit('user/setCurrentUser', response.data.user, { root: true });
|
|
|
|
|
commit('user/setCurrentPermissions', response.data.permissions, {
|
|
|
|
|
root: true,
|
|
|
|
|
root: true
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((error: AxiosError) => {
|
|
|
|
@ -78,7 +78,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
*/
|
|
|
|
|
logout({ dispatch, rootState }) {
|
|
|
|
|
if (rootState.session.currentSession) {
|
|
|
|
|
dispatch('deleteSession', rootState.session.currentSession.token).catch((error) => {
|
|
|
|
|
dispatch('deleteSession', rootState.session.currentSession.token).catch(error => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
void dispatch('clearCurrent', false);
|
|
|
|
|
});
|
|
|
|
@ -97,7 +97,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
if (token === rootState.session.currentSession?.token) {
|
|
|
|
|
void dispatch('clearCurrent', false);
|
|
|
|
|
} else {
|
|
|
|
|
dispatch('getSessions').catch((error) => {
|
|
|
|
|
dispatch('getSessions').catch(error => {
|
|
|
|
|
throw error;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -116,7 +116,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
void Router.push({
|
|
|
|
|
name: 'login',
|
|
|
|
|
query: redirect ? { redirect: Router.currentRoute.fullPath } : {},
|
|
|
|
|
params: { logout: 'true' },
|
|
|
|
|
params: { logout: 'true' }
|
|
|
|
|
}).then(() => {
|
|
|
|
|
commit('clearCurrentSession');
|
|
|
|
|
commit('user/clearCurrentUser', null, { root: true });
|
|
|
|
@ -132,7 +132,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
axios
|
|
|
|
|
.get('/auth')
|
|
|
|
|
.then((response: AxiosResponse<FG.Session[]>) => {
|
|
|
|
|
response.data.forEach((session) => {
|
|
|
|
|
response.data.forEach(session => {
|
|
|
|
|
session.expires = new Date(session.expires);
|
|
|
|
|
});
|
|
|
|
|
commit('setSessions', response.data);
|
|
|
|
@ -143,7 +143,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
commit('setCurrentSession', currentSession);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
.catch(error => {
|
|
|
|
|
throw error;
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
@ -160,7 +160,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
commit('setCurrentSession', response.data);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => console.log(err))
|
|
|
|
|
.catch(err => console.log(err))
|
|
|
|
|
.finally(() => {
|
|
|
|
|
commit('setLoading', false);
|
|
|
|
|
});
|
|
|
|
@ -173,7 +173,7 @@ const actions: ActionTree<SessionInterface, StateInterface> = {
|
|
|
|
|
return axios.post('/auth/reset', data).catch((error: AxiosError) => {
|
|
|
|
|
return Promise.reject(error.response);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getters: GetterTree<SessionInterface, StateInterface> = {
|
|
|
|
@ -185,7 +185,7 @@ const getters: GetterTree<SessionInterface, StateInterface> = {
|
|
|
|
|
},
|
|
|
|
|
loading(state) {
|
|
|
|
|
return state.loading;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sessions: Module<SessionInterface, StateInterface> = {
|
|
|
|
@ -193,7 +193,7 @@ const sessions: Module<SessionInterface, StateInterface> = {
|
|
|
|
|
state,
|
|
|
|
|
mutations,
|
|
|
|
|
actions,
|
|
|
|
|
getters,
|
|
|
|
|
getters
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default sessions;
|
|
|
|
|