diff --git a/lib/www/client/source/src/store/modules/user/actions.js b/lib/www/client/source/src/store/modules/user/actions.js index 2790136..38d0cff 100644 --- a/lib/www/client/source/src/store/modules/user/actions.js +++ b/lib/www/client/source/src/store/modules/user/actions.js @@ -11,7 +11,7 @@ async function login ({commit, dispatch}, loginRequest) { } const res = await dispatch('api', [url, init]); if (res && res.ok) { - await dispatch('setCredentials', true); + await dispatch('setCredentials', {force: true}); await dispatch('loadUserPreferences'); } } @@ -34,12 +34,12 @@ function cookieChanged (cookie) { return browserCookie != cookie; } -function setCredentials ({state, commit, getters, dispatch}, force = false) { - if (cookieChanged(state.cookie) || force) { +function setCredentials ({state, commit, getters, dispatch}, {force, token} = {}) { + if (token || force || cookieChanged(state.cookie)) { try { const cookie = browserCookie(); - const decoded = cookie ? jwt_decode(cookie.split("=")[1]) : null; - commit('setCookie', cookie); + const decoded = (token ?? cookie) ? jwt_decode(token ?? cookie.split("=")[1]) : null; + commit('setCookie', (cookie ?? (token && ("JWT="+token))) || undefined); commit('setUser', decoded); } catch (err) { if (err.name == "InvalidTokenError") { @@ -54,7 +54,7 @@ function setCredentials ({state, commit, getters, dispatch}, force = false) { /** * Save user preferences to localStorage and store. - * + * * User preferences are identified by a key that gets * prefixed with the user name and role. The value can * be anything that JSON.stringify can parse.