mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:27:08 +00:00
Set cookie / user to null if failing to decode JWT
This commit is contained in:
@@ -32,9 +32,19 @@ function cookieChanged (cookie) {
|
||||
|
||||
function setCredentials ({state, commit, getters, dispatch}, force = false) {
|
||||
if (cookieChanged(state.cookie) || force) {
|
||||
const cookie = browserCookie();
|
||||
commit('setCookie', cookie);
|
||||
commit('setUser', cookie ? jwt_decode(cookie.split("=")[1]) : null);
|
||||
try {
|
||||
const cookie = browserCookie();
|
||||
const decoded = jwt_decode(cookie.split("=")[1]);
|
||||
commit('setCookie', cookie);
|
||||
commit('setUser', decoded);
|
||||
} catch (err) {
|
||||
if (err.name == "InvalidTokenError") {
|
||||
commit('setCookie', null);
|
||||
commit('setUser', null);
|
||||
} else {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user