fix: refresh auth token on tab visibility change to prevent logout after inactivity
This commit is contained in:
@@ -47,6 +47,7 @@ class DirectusService {
|
||||
this.refreshTimeout = null
|
||||
|
||||
this.loadTokens()
|
||||
this.setupVisibilityRefresh()
|
||||
}
|
||||
|
||||
// ==================== Token Management ====================
|
||||
@@ -109,6 +110,17 @@ class DirectusService {
|
||||
}
|
||||
}
|
||||
|
||||
setupVisibilityRefresh() {
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible' && this.refreshToken) {
|
||||
const timeLeft = this.tokenExpiry - Date.now()
|
||||
if (timeLeft < 60000) {
|
||||
this.refreshSession()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
isAuthenticated() {
|
||||
return !!this.accessToken && (!this.tokenExpiry || Date.now() < this.tokenExpiry)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user