fix(auth): silently discard invalid auth tokens and log the user out
This commit is contained in:
parent
8507808058
commit
287daf9125
@ -226,15 +226,20 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
const jwt = getToken()
|
const jwt = getToken()
|
||||||
let isAuthenticated = false
|
let isAuthenticated = false
|
||||||
if (jwt) {
|
if (jwt) {
|
||||||
const base64 = jwt
|
try {
|
||||||
.split('.')[1]
|
const base64 = jwt
|
||||||
.replace('-', '+')
|
.split('.')[1]
|
||||||
.replace('_', '/')
|
.replace('-', '+')
|
||||||
const info = new UserModel(JSON.parse(atob(base64)))
|
.replace('_', '/')
|
||||||
const ts = Math.round((new Date()).getTime() / MILLISECONDS_A_SECOND)
|
const info = new UserModel(JSON.parse(atob(base64)))
|
||||||
isAuthenticated = info.exp >= ts
|
const ts = Math.round((new Date()).getTime() / MILLISECONDS_A_SECOND)
|
||||||
// Settings should only be loaded from the api request, not via the jwt
|
|
||||||
setUser(info, false)
|
isAuthenticated = info.exp >= ts
|
||||||
|
// Settings should only be loaded from the api request, not via the jwt
|
||||||
|
setUser(info, false)
|
||||||
|
} catch (e) {
|
||||||
|
logout()
|
||||||
|
}
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
await refreshUserInfo()
|
await refreshUserInfo()
|
||||||
@ -292,11 +297,14 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
|
|
||||||
return newUser
|
return newUser
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if(e?.response?.data?.message === 'invalid or expired jwt') {
|
if(e?.response?.status === 401 ||
|
||||||
logout()
|
e?.response?.data?.message === 'missing, malformed, expired or otherwise invalid token provided') {
|
||||||
|
await logout()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('continuerd')
|
||||||
|
|
||||||
const cause = {e}
|
const cause = {e}
|
||||||
|
|
||||||
if (typeof e?.response?.data?.message !== 'undefined') {
|
if (typeof e?.response?.data?.message !== 'undefined') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user