Add timeout to fix race condition when authenticating as a link share and renewing the token simultaneously

Related #587
This commit is contained in:
kolaente 2021-07-10 12:32:04 +02:00
parent a787f6ffc7
commit 20fd25e280
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -214,6 +214,10 @@ 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) {
// Timeout to avoid race conditions when authenticated as a user (=auth token in localStorage) and as a
// 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) { if (!ctx.state.authenticated) {
return return
} }
@ -229,6 +233,7 @@ export default {
ctx.dispatch('logout') ctx.dispatch('logout')
} }
}) })
}, 5000)
}, },
logout(ctx) { logout(ctx) {
removeToken() removeToken()