fix: return to login when the stored token is revoked
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Verify the saved access token in the /_api guard (it was commented out) and clear storage/redirect to /login/manual on 401. Also catch fetchCurrentUser failures during startup.
This commit is contained in:
1 parent
dd0bf8b493
commit
a07ae9b264
2 files changed
+32
-17
No files matched your search
+11
-2
@@ -10,6 +10,7 @@ import {
|
||||
useApiInContext,
|
||||
} from "./utils/store/api";
|
||||
import { CentralProvider, useCentralStore } from "./utils/store/central";
|
||||
import { delUser } from "./utils/storage/user";
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -67,9 +68,17 @@ function ProviderWrapper() {
|
||||
]);
|
||||
useEffect(() => {
|
||||
if (api?.accessToken && !user?.Id) {
|
||||
fetchCurrentUser(api);
|
||||
fetchCurrentUser(api).catch(async (error) => {
|
||||
console.error("Could not restore the saved session", error);
|
||||
await delUser();
|
||||
createApi(api.basePath, undefined);
|
||||
router.navigate({
|
||||
to: "/login/manual",
|
||||
search: { redirect: window.location.pathname },
|
||||
});
|
||||
});
|
||||
}
|
||||
}, [api, user, fetchCurrentUser]);
|
||||
}, [api, user, fetchCurrentUser, createApi]);
|
||||
useEffect(() => {
|
||||
if (api) {
|
||||
console.log(`API is set - Route ${window.location.pathname}`);
|
||||
|
||||
Reference in new issue
Block a user