diff --git a/src/plugins/user/components/settings/Sessions.vue b/src/plugins/user/components/settings/Sessions.vue index 1932931..c609bef 100644 --- a/src/plugins/user/components/settings/Sessions.vue +++ b/src/plugins/user/components/settings/Sessions.vue @@ -16,22 +16,42 @@ {{ session.platform }} -
+
Lebenszeit: {{ session.lifetime }}
Läuft aus: {{ session.expires | dateTime(true) }}
+
+ + +
- + + + + + + diff --git a/src/plugins/user/store/session.ts b/src/plugins/user/store/session.ts index 2428cc8..5c4f4ab 100644 --- a/src/plugins/user/store/session.ts +++ b/src/plugins/user/store/session.ts @@ -25,7 +25,7 @@ function loadCurrentSession() { const state: SessionInterface = { sessions: [], currentSession: loadCurrentSession() || undefined, - loading: false + loading: false, }; const mutations: MutationTree = { @@ -42,7 +42,13 @@ const mutations: MutationTree = { }, setLoading(state, value: boolean) { state.loading = value; - } + }, + updateSession(state, session: FG.Session) { + const index = state.sessions.findIndex((x) => x.token == session.token); + if (index > -1) { + state.sessions[index] = session; + } + }, }; const actions: ActionTree = { @@ -59,7 +65,7 @@ const actions: ActionTree = { 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) => { @@ -72,7 +78,7 @@ const actions: ActionTree = { */ 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); }); @@ -91,7 +97,7 @@ const actions: ActionTree = { if (token === rootState.session.currentSession?.token) { void dispatch('clearCurrent', false); } else { - dispatch('getSessions').catch(error => { + dispatch('getSessions').catch((error) => { throw error; }); } @@ -110,7 +116,7 @@ const actions: ActionTree = { 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 }); @@ -126,7 +132,7 @@ const actions: ActionTree = { axios .get('/auth') .then((response: AxiosResponse) => { - response.data.forEach(session => { + response.data.forEach((session) => { session.expires = new Date(session.expires); }); commit('setSessions', response.data); @@ -137,13 +143,29 @@ const actions: ActionTree = { commit('setCurrentSession', currentSession); } }) - .catch(error => { + .catch((error) => { throw error; }) .finally(() => { commit('setLoading', false); }); }, + updateSession({ commit, state }, data: { lifetime: number; token: string }) { + commit('setLoading', true); + axios + .put(`auth/${data.token}`, { value: data.lifetime }) + .then((response: AxiosResponse) => { + response.data.expires = new Date(response.data.expires); + if (state.currentSession?.token == response.data.token) { + commit('setCurrentSession', response.data); + } + }) + .catch((err) => console.log(err)) + .finally(() => { + commit('setLoading', false); + }); + console.log('updateSession', data); + }, requestPasswordReset({}, data) { return axios.post('/auth/reset', data); }, @@ -151,7 +173,7 @@ const actions: ActionTree = { return axios.post('/auth/reset', data).catch((error: AxiosError) => { return Promise.reject(error.response); }); - } + }, }; const getters: GetterTree = { @@ -163,7 +185,7 @@ const getters: GetterTree = { }, loading(state) { return state.loading; - } + }, }; const sessions: Module = { @@ -171,7 +193,7 @@ const sessions: Module = { state, mutations, actions, - getters + getters, }; export default sessions;