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

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:
1xDed committed 2026-11-27 14:40:51 +03:00
1 parent dd0bf8b493
commit a07ae9b264
2 files changed
+32 -17

No files matched your search

+11 -2
View File
@@ -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}`);
+21 -15
View File
@@ -1,5 +1,5 @@
import { getDefaultServer, getServer } from "@/utils/storage/servers";
import { getUser } from "@/utils/storage/user";
import { delUser, getUser } from "@/utils/storage/user";
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { createFileRoute, redirect } from "@tanstack/react-router";
@@ -56,20 +56,26 @@ export const Route = createFileRoute("/_api")({
}
}
} else if (context.api) {
// if (context.api.accessToken && location.pathname !== "/login/manual") {
// try {
// console.info("AccessToken", context.api.accessToken);
// await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate
// } catch (error) {
// console.error(error);
// throw redirect({
// to: "/login/manual",
// search: {
// redirect: location.href,
// },
// });
// }
// }
// The API was created from a token stored on disk. The token can be
// revoked (logged out everywhere / server reset); verify it and send
// the user back to the login page instead of leaving a broken page.
const isAuthPage =
location.pathname.startsWith("/login") ||
location.pathname.startsWith("/setup") ||
location.pathname.startsWith("/error");
if (context.api.accessToken && !isAuthPage) {
try {
await getUserApi(context.api).getCurrentUser();
} catch (error) {
console.error("Stored access token is no longer valid", error);
await delUser();
context.createApi(context.api.basePath, undefined);
throw redirect({
to: "/login/manual",
search: { redirect: location.href },
});
}
}
}
},
});