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);