Add timeout to fix race condition when authenticating as a link share and renewing the token simultaneously
Related #587
This commit is contained in:
parent
a787f6ffc7
commit
20fd25e280
1 changed files with 19 additions and 14 deletions
|
@ -214,21 +214,26 @@ export default {
|
||||||
},
|
},
|
||||||
// Renews the api token and saves it to local storage
|
// Renews the api token and saves it to local storage
|
||||||
renewToken(ctx) {
|
renewToken(ctx) {
|
||||||
if (!ctx.state.authenticated) {
|
// Timeout to avoid race conditions when authenticated as a user (=auth token in localStorage) and as a
|
||||||
return
|
// link share in another tab. Without the timeout both the token renew and link share auth are executed at
|
||||||
}
|
// the same time and one might win over the other.
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!ctx.state.authenticated) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
refreshToken()
|
refreshToken()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
ctx.dispatch('checkAuth')
|
ctx.dispatch('checkAuth')
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
// Don't logout on network errors as the user would then get logged out if they don't have
|
// Don't logout on network errors as the user would then get logged out if they don't have
|
||||||
// internet for a short period of time - such as when the laptop is still reconnecting
|
// internet for a short period of time - such as when the laptop is still reconnecting
|
||||||
if (e.request.status) {
|
if (e.request.status) {
|
||||||
ctx.dispatch('logout')
|
ctx.dispatch('logout')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}, 5000)
|
||||||
},
|
},
|
||||||
logout(ctx) {
|
logout(ctx) {
|
||||||
removeToken()
|
removeToken()
|
||||||
|
|
Loading…
Reference in a new issue