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, useApiInContext,
} from "./utils/store/api"; } from "./utils/store/api";
import { CentralProvider, useCentralStore } from "./utils/store/central"; import { CentralProvider, useCentralStore } from "./utils/store/central";
import { delUser } from "./utils/storage/user";
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
@@ -67,9 +68,17 @@ function ProviderWrapper() {
]); ]);
useEffect(() => { useEffect(() => {
if (api?.accessToken && !user?.Id) { 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(() => { useEffect(() => {
if (api) { if (api) {
console.log(`API is set - Route ${window.location.pathname}`); 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 { 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 { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { createFileRoute, redirect } from "@tanstack/react-router"; import { createFileRoute, redirect } from "@tanstack/react-router";
@@ -56,20 +56,26 @@ export const Route = createFileRoute("/_api")({
} }
} }
} else if (context.api) { } else if (context.api) {
// if (context.api.accessToken && location.pathname !== "/login/manual") { // The API was created from a token stored on disk. The token can be
// try { // revoked (logged out everywhere / server reset); verify it and send
// console.info("AccessToken", context.api.accessToken); // the user back to the login page instead of leaving a broken page.
// await getUserApi(context.api).getCurrentUser(); // Verify user is able to authenticate const isAuthPage =
// } catch (error) { location.pathname.startsWith("/login") ||
// console.error(error); location.pathname.startsWith("/setup") ||
// throw redirect({ location.pathname.startsWith("/error");
// to: "/login/manual", if (context.api.accessToken && !isAuthPage) {
// search: { try {
// redirect: location.href, 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 },
});
}
}
} }
}, },
}); });