aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/api/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/api/client.ts')
-rw-r--r--src/client/api/client.ts28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/client/api/client.ts b/src/client/api/client.ts
index fc718a2..539df8b 100644
--- a/src/client/api/client.ts
+++ b/src/client/api/client.ts
@@ -101,16 +101,22 @@ export class ApiClient {
const response = await fetch(input, { ...init, headers });
- if (response.status === 401 && tokens?.refreshToken) {
- // Try to refresh the token
- const refreshed = await this.refreshToken();
- if (refreshed) {
- // Retry with new token
- const newTokens = this.tokenStorage.getTokens();
- if (newTokens?.accessToken) {
- headers.set("Authorization", `Bearer ${newTokens.accessToken}`);
+ if (response.status === 401 && tokens?.accessToken) {
+ if (tokens.refreshToken) {
+ // Try to refresh the token
+ const refreshed = await this.refreshToken();
+ if (refreshed) {
+ // Retry with new token
+ const newTokens = this.tokenStorage.getTokens();
+ if (newTokens?.accessToken) {
+ headers.set("Authorization", `Bearer ${newTokens.accessToken}`);
+ }
+ return fetch(input, { ...init, headers });
}
- return fetch(input, { ...init, headers });
+ } else {
+ // No refresh token available — treat as session expiry
+ this.tokenStorage.clearTokens();
+ this.sessionExpiredCallback?.();
}
}
@@ -205,10 +211,6 @@ export class ApiClient {
this.tokenStorage.clearTokens();
}
- isAuthenticated(): boolean {
- return this.tokenStorage.getTokens() !== null;
- }
-
getTokens(): Tokens | null {
return this.tokenStorage.getTokens();
}