Repository navigation
Description
Describe the bug
When I refresh the panel while already logged in, I sometimes briefly get shown the login page before being sent straight back to the panel.
It seems like the panel might be deciding where to send me before it's actually finished checking whether I'm logged in. It's not a major issue on its own, but ideally I shouldn't be seeing the login page at all if my session is still valid.
To Reproduce
- Log in to the Catalyst panel.
- Navigate to a page like
/serversor/dashboard. - Refresh the tab.
- The login page may briefly appear before the panel loads normally.
Expected behavior
Refreshing with a valid session should keep me on the page I was on. The panel should finish checking the existing session before deciding whether to show the login page or continue to the panel.
Desktop
- OS: Fedora Linux
- Browser: Zen
Additional context
I had a look through the authentication code and noticed something that might explain this.
In authStore.ts, refresh() sets isReady: true before awaiting the session check:
refresh: async () => {
set({ isRefreshing: true, error: null, isReady: true });
try {
const { user } = await authApi.refresh();What's readable is that init() even has a comment saying not to mark authentication as ready until refresh completes, but refresh() itself appears to do exactly that.
Looking at how the rest fits together:
- App.tsx uses
isReadyas part of its initial loading check. - ProtectedRoute.tsx redirects to
/loginifisReadyis true butisAuthenticatedis false. - LoginPage.tsx redirects authenticated users back to the panel.
So I'm wondering if there's a window where the panel considers authentication ready, sees that I'm not authenticated yet, sends me to login, and then sends me straight back once the session check finishes.
I can't say for certain that's what's happening without tracing it at runtime, but the code seems to allow that sequence.
I also noticed that useAuthInit.ts has a timeout that can independently mark authentication ready, while client.ts can reset authentication state on 401 responses.
It might be worth looking at how these interact, especially when the backend is slow or requests overlap. I'd be more concerned about inconsistent session handling than the brief login-page flash itself.
From what I could see, protected routes still check authentication and permissions, so I haven't found anything suggesting an authorization bypass, if that is a concern of yours (since I am bringing up authorization state race conditions).
Ideally, the initial session check should finish before the panel makes a decision about where to send the user, rather than potentially bouncing through login first.
Activity
pullfrog commentedon Nov 16, 2026
Diagnosis
The reporter's read of the code is correct, and there is a second, worse path they did not find.
refresh()opens withset({ isRefreshing: true, error: null, isReady: true })(catalyst-frontend/src/stores/authStore.ts:162).App.tsx:213gates the whole router onisReady,ProtectedRouterenders a spinner untilisReadyand then<Navigate to="/login">whenisAuthenticatedis false, andLoginPageredirects back once authentication lands. So the store is announcing "auth decided" before it has decided anything, which is exactly the bounce the issue describes.Every caller of
refresh()outside boot inherits that write:useProfileSync(polls/api/auth/meon mount and every 60 s),useSseAdminEventsanduseServerStateUpdates(onuser_updated/permissions_updated), andProfilePage(after profile, avatar and password mutations). On a real-time page a single SSE event can therefore remount the router while the session is momentarily unresolved — the "more concerned about inconsistent session handling than the flash" part of the report.Three things amplify it:
isRefreshing: false, isReady: truebut leavesuserandisAuthenticatedalone.LoginPageonly redirects whenisAuthenticatedis true, so a background refresh that hits a 500 while the user sits on/login(or is bounced there by something else) strands an authenticated user on the sign-in form. Failures also set noerror, so nothing is visible either.isReadybackdoor inuseAuthInitandApp. The 12 s init timeout (useAuthInit.ts:14) and the 20 s boot backstop (App.tsx:122) both flipisReadywhile the session probe is still in flight, with no way for the laterefresh()to undo a prematurefalse.isReadywriters with no ordering. Thestoragelistener inauthStore.ts:322callsinit()on every cross-tabcatalyst-authwrite, andlogout()re-writescatalyst-auth, so a tab can run overlappingrefresh()calls (deduped at the request layer, not the store layer) whosefinallysetsisRefreshing: falsewhile another is still running.Good news for correctness:
client.tsbypasses the global 401 handling for/api/auth/me, so a noisy session probe cannot itself clear state. This is a bad route decision, not an authorization bypass —ProtectedRoutestill checks permissions afterisReady, so a session that resolves after an early/loginbounce simply gets redirected back.Plan
1. Make
isReadymean "the session question is answered" (authStore.ts)refresh()no longer writesisReady. Add a module-level in-flight counter increateAuthState's closure; thefinallyblock clearsisRefreshingand setsisReady: trueonly when no other refresh is in flight (last one wins).init()keeps sole ownership of the boot transition:await refresh()in atry/catch, then setisReady: trueinfinally.error(getLocalizedErrorMessage(err)) soLoginPagecan explain the state instead of showing a blank form. Add a dedicated translated key (e.g.auth:errors.sessionCheckFailed) rather than reusing a generic one; runpnpm --filter catalyst-frontend run i18n:extractand fillfr+zh-CNin the same change.loginGuard.activeshort-circuit: keep the session and return without marking ready (boot is owned bylogin, whose ownisReady: trueis correct there).2. Tighten the timeout backdoors (
useAuthInit.ts,App.tsx)isReady, re-run the session probe once (capped retry). If it still does not settle, keep the current fail-open (isReady: true) but route to a "couldn't check your session — retry" state rather than a bare/login; the retry reusesinit(). This is the path a slow backend takes, so it is where the flash is most likely in practice.Appbackstop: only flipbootTimedOutwhen bothisReadyis false and no refresh is in flight, or drop the flag for auth entirely — it currently duplicatesuseAuthInit's job.useSetupStatus's fast path untouched; it already routes immediately when install memory exists.3. Stop remounting the router from background refreshes
Audit the four
refresh()call sites (useProfileSync,useSseAdminEvents:248,useServerStateUpdates:302,ProfilePage). Once step 1 lands they no longer moveisReady, but they should not need to touchisRefreshingeither —useProfileSyncin particular can switch to a display-fields-only patch (it already hassyncDisplayFieldsToStore) and drop itsauthApi.refresh()round trip entirely.Also verify the
await import('../lib/queryClient')insidelogout()—queryClient.ts:56re-exports the class, so check the import resolves to the singleton instance and clear the right client.4. Regression tests (vitest,
src/stores/__tests__/authStore.test.ts, new file)Fake timers plus a stubbed
authApi.refresh:refresh()alone never setsisReady— the exact assert on the reported line.init()setsisReadyonly after the probe settles, for success, 401 and transient failure.isAuthenticated: true, setserror, and leavesisReadyuntouched when called post-boot.init()/refresh()calls:isReadyflips exactly once and the last settle wins.services/api/__tests__/client.test.ts: a 401 on/api/auth/medoes not clear state.5. E2E guard (
catalyst-frontend/e2e/functional.spec.ts, Authentication Flows)After
login(page), assert the URL never passes through/loginon a reload: install apage.on('framenavigated')recorder beforepage.goto('/servers')and expect the final URL to be/serverswith no/loginentry. Repeat with/api/auth/medelayed viapage.route(e.g. 2 s) to force the slow-backend window — this is the scenario the issue reports and the one a plain reload will not reproduce reliably.6. Verify and ship
pnpm --filter catalyst-frontend run lint,cd catalyst-frontend && npx tsc --noEmit,pnpm --filter catalyst-frontend exec vitest run,pnpm i18n:check,pnpm i18n:hardcoded,pnpm --filter catalyst-frontend run i18n:verify.AGENTS.md, check it in the browser: sign in, reload on/serversand/dashboardwith a throttled backend, and confirm no/loginpaint.catalyst-docrepo; note the session-bootstrap behaviour there if a page covers auth/session handling.fix(frontend): don't mark auth ready before the session check settles, to prevent the login-page flash on reload (closes #360)and land via push tomainunless a PR is requested.Out of scope
No backend change is needed —
/api/auth/mealready caches its response for 5 s (catalyst-backend/src/routes/auth.ts:35) and is exempt from the global 401 handling on the client.pullfrog| 𝕏pullfrog commentedon Nov 17, 2026
Implemented the plan and opened #361.
refresh()no longer writesisReady(an in-flight counter gatesisRefreshing);init()is the only boot writer. A transient probe failure keeps the session and sets a translated error, and a boot probe that fails or never settles now leads to a retry screen inAppinstead of a bare/login. The 12s hook deadline re-arms once before failing open, and the 20s App backstop no longer overrides an in-flight probe.Two corrections to the plan's premises:
/api/auth/mewas not exempt from the global 401 handling (only from the redirect — it still cleared state and cache), so the interceptor now skips state/cache clearing for public endpoints and the store'srefresh()owns sign-out and cache clearing; anduseProfileSyncalready usedauthApi.refresh()with a display-fields patch, so it needed no change.Regression tests cover the store's readiness ordering, overlapping probes, failed retries and the probe's 401, plus two Playwright reload guards (one with
/api/auth/medelayed 2s) that fail if the app ever navigates through/login.tsc, lint, the full vitest suite (693 tests) and all i18n checks pass; a live browser check was not possible here (no database, docker daemon or Playwright browsers), so that path relies on the new e2e specs.Task list (1/8 completed)
pullfrog| 𝕏