mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:45 +00:00
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>
This commit is contained in:
@@ -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<boolean> {
|
||||
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<UserMeResponse | false> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user