From 4bbdaa06a97d35e0bd360c6cf7ad73710fb42112 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 1 Mar 2025 11:30:30 +0100 Subject: [PATCH] Refactor auth handling to improve token refresh logic --- src/components/repo/authv2.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/repo/authv2.ts b/src/components/repo/authv2.ts index 0fc85b1..048da51 100644 --- a/src/components/repo/authv2.ts +++ b/src/components/repo/authv2.ts @@ -133,7 +133,14 @@ export class AuthV2Repo { try { const response = await this.requestWithToken(this.refreshToken!, "/auth", { method: "PUT", - }).then(value => value.json()).then(value => AuthTokenSchema.parse(value)); + }).then(value => { + if (value.status === 401) { + throw new Error("Unauthorized"); + } + + return value; + }).then(value => value.json()) + .then(value => AuthTokenSchema.parse(value)); this.setLoginState(response); } catch (e) { @@ -163,7 +170,7 @@ export class AuthV2Repo { }, }) .then(value => { - if (value.status === 401) { + if (value.status === 401 && url !== "/auth") { this.refresh(); return this.requestWithToken(token, url, params, retryCount + 1);