From 3870733ba4069ed411d6785c501b4e7abea4f894 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 16 Jun 2025 20:31:07 -0400 Subject: [PATCH] Improve handling of HTTP 401 (#1194) ## Description: Improve handling of HTTP 401 by deleting the access token so that the token will not be used again. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/client/jwt.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/client/jwt.ts b/src/client/jwt.ts index 4fdf8ae15..fcb3b8dac 100644 --- a/src/client/jwt.ts +++ b/src/client/jwt.ts @@ -133,6 +133,7 @@ function _isLoggedIn(): IsLoggedInResponse { console.log("Refreshed access token successfully."); } else { console.error("Failed to refresh access token."); + // TODO: Update the UI to show logged out state } }); } @@ -165,6 +166,11 @@ export async function postRefresh(): Promise { authorization: `Bearer ${token}`, }, }); + if (response.status === 401) { + localStorage.removeItem("token"); + __isLoggedIn = false; + return false; + } if (response.status !== 200) return false; const body = await response.json(); const result = RefreshResponseSchema.safeParse(body); @@ -192,6 +198,11 @@ export async function getUserMe(): Promise { authorization: `Bearer ${token}`, }, }); + if (response.status === 401) { + localStorage.removeItem("token"); + __isLoggedIn = false; + return false; + } if (response.status !== 200) return false; const body = await response.json(); const result = UserMeResponseSchema.safeParse(body);