reduce shadow logouts, by actually logging out when token fails or is expired
All checks were successful
/ deploy (push) Successful in 4m33s
/ test (push) Successful in 2m56s

This commit is contained in:
j3d1 2024-12-24 15:55:07 +01:00
parent 66a03a9dca
commit 598f758332
5 changed files with 46 additions and 7 deletions

View file

@ -20,6 +20,9 @@ export default (config) => (store) => {
}
});
store.state[config.isLoadedKey] = true;
if ('validate' in config) {
config.validate(store.state);
}
}
const reload = initialize;

View file

@ -515,6 +515,15 @@ const store = createStore({
prefix: "lf_",
debug: false,
isLoadedKey: "persistent_loaded",
validate: (state) => {
if (state.user && state.user.expiry && state.user.token) {
const as_date = new Date(state.user.expiry);
if (as_date < new Date()) {
state.user.token = null;
state.user.expiry = null;
}
}
},
state: ["remember", "user", "events", "lastUsed",]
}), sharedStatePlugin({
debug: false,

View file

@ -1,3 +1,5 @@
import store from '@/store'
function ticketStateColorLookup(ticket) {
if (ticket.startsWith('closed_')) {
return 'secondary';
@ -36,6 +38,8 @@ const http = {
"Authorization": `Token ${token}`,
},
});
if (response.status === 401)
throw {http_status: response.status};
const success = response.status === 200 || response.status === 201;
return {data: await response.json() || {}, success};
},
@ -51,6 +55,8 @@ const http = {
},
body: JSON.stringify(data),
});
if (response.status === 401)
throw {http_status: response.status};
const success = response.status === 200 || response.status === 201;
return {data: await response.json() || {}, success};
},
@ -66,6 +72,8 @@ const http = {
},
body: JSON.stringify(data),
});
if (response.status === 401)
throw {http_status: response.status};
const success = response.status === 200 || response.status === 201;
return {data: await response.json() || {}, success};
},
@ -81,6 +89,8 @@ const http = {
},
body: JSON.stringify(data),
});
if (response.status === 401)
throw {http_status: response.status};
const success = response.status === 200 || response.status === 201;
return {data: await response.json() || {}, success};
},
@ -95,17 +105,34 @@ const http = {
"Authorization": `Token ${token}`,
},
});
if (response.status === 401)
throw {http_status: response.status};
const success = response.status === 204;
return {data: await response.text() || {}, success};
}
}
const http_session = token => ({
get: async (url) => await http.get(url, token),
post: async (url, data) => await http.post(url, data, token),
put: async (url, data) => await http.put(url, data, token),
patch: async (url, data) => await http.patch(url, data, token),
delete: async (url) => await http.delete(url, token),
get: async (url) => await http.get(url, token).catch((e) => {
if (e.http_status === 401) store.commit('logout');
return {data: {}, success: false};
}),
post: async (url, data) => await http.post(url, data, token).catch((e) => {
if (e.http_status === 401) store.commit('logout');
return {data: {}, success: false};
}),
put: async (url, data) => await http.put(url, data, token).catch((e) => {
if (e.http_status === 401) store.commit('logout');
return {data: {}, success: false};
}),
patch: async (url, data) => await http.patch(url, data, token).catch((e) => {
if (e.http_status === 401) store.commit('logout');
return {data: {}, success: false};
}),
delete: async (url) => await http.delete(url, token).catch((e) => {
if (e.http_status === 401) store.commit('logout');
return {data: {}, success: false};
}),
});
export {ticketStateColorLookup, ticketStateIconLookup, http, http_session};

View file

@ -72,7 +72,7 @@ export default {
name: 'Login',
data() {
return {
msg: 'Welcome to ' + window.location.hostname,
msg: 'Lost&Found Team Login',
username: '',
password: '',
remember: false

View file

@ -87,7 +87,7 @@ export default {
name: 'Register',
data() {
return {
msg: 'Register',
msg: 'Register as team member',
password2: '',
form: {
username: '',