mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix for SDK - Persistent login refresh not working (#4113)
This commit is contained in:
@@ -41,7 +41,7 @@ export class AuthHandler {
|
||||
this.accessTokenInitId = this.axios.interceptors.request.use((config) => this.initializeAccessToken(config));
|
||||
|
||||
if (this.autoRefresh) {
|
||||
this.refresh();
|
||||
this.refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export class AuthHandler {
|
||||
await this.storage.setItem('directus_refresh_token', data.refresh_token);
|
||||
}
|
||||
if (this.autoRefresh) {
|
||||
this.refresh();
|
||||
this.refresh(true);
|
||||
}
|
||||
|
||||
return response.data;
|
||||
@@ -84,15 +84,17 @@ export class AuthHandler {
|
||||
/**
|
||||
* Refresh access token 10 seconds before expiration
|
||||
*/
|
||||
async refresh(): Promise<{ data: AuthResponse } | undefined> {
|
||||
async refresh(isInitialInvoke: Boolean): Promise<{ data: AuthResponse } | undefined> {
|
||||
this.removeTimeout();
|
||||
|
||||
this.expiresAt = await this.storage.getItem('directus_access_token_expires');
|
||||
if (!this.expiresAt) return;
|
||||
|
||||
if (Date.now() + 10000 < this.expiresAt && this.autoRefresh) {
|
||||
this.autoRefreshTimeout = setTimeout(() => this.refresh(), this.expiresAt - Date.now() - 10000);
|
||||
return;
|
||||
this.autoRefreshTimeout = setTimeout(() => this.refresh(false), this.expiresAt - Date.now() - 10000);
|
||||
if (!isInitialInvoke) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const payload: Record<string, any> = { mode: this.mode };
|
||||
@@ -118,7 +120,7 @@ export class AuthHandler {
|
||||
}
|
||||
|
||||
if (this.autoRefresh) {
|
||||
this.autoRefreshTimeout = setTimeout(() => this.refresh(), data.expires - 10000);
|
||||
this.autoRefreshTimeout = setTimeout(() => this.refresh(false), data.expires - 10000);
|
||||
}
|
||||
return response.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user