Skip to content

fix: Authenticated page race condition#198

Merged
hhvrc merged 18 commits into
developfrom
fix/authed-page-race-condition
May 17, 2026
Merged

fix: Authenticated page race condition#198
hhvrc merged 18 commits into
developfrom
fix/authed-page-race-condition

Conversation

@hhvrc
Copy link
Copy Markdown
Contributor

@hhvrc hhvrc commented May 15, 2026

No description provided.

@hhvrc hhvrc self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 21:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to eliminate an authenticated-route race condition by moving the auth/bootstrap gating to the (app) layout and shifting some page-level data fetching from SvelteKit load functions into client-side component logic.

Changes:

  • Add an auth gate in src/routes/(app)/+layout.ts that awaits a memoized backend/user bootstrap and redirects unauthenticated users to /login?next=....
  • Consolidate backend bootstrap (backend metadata fetch + userState.refreshSelf() + SignalR init) into backendMetadata.init() and invoke it during hydration.
  • Replace +page.ts loads for shocker log pages with onMount-based fetching; refactor API token list refresh logic.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/routes/(app)/shockers/logs/+page.ts Removes page load that previously fetched all shocker logs.
src/routes/(app)/shockers/logs/+page.svelte Fetches all shocker logs on mount and binds the table to local state.
src/routes/(app)/shockers/logs/[shockerId=guid]/+page.ts Removes page load that previously fetched per-shocker logs/details.
src/routes/(app)/shockers/logs/[shockerId=guid]/+page.svelte Fetches per-shocker logs/details on mount and binds the table to local state.
src/routes/(app)/settings/api-tokens/+page.svelte Renames/cleans token state handling and introduces a refresh() helper.
src/routes/(app)/+layout.ts Introduces an auth gate in layout load() for (app) routes.
src/routes/(app)/+layout.svelte Simplifies rendering and keeps a client-side “logged out” redirect safety net.
src/lib/state/backend-metadata-state.svelte.ts Memoizes bootstrap and changes init() to return an “authenticated and ready” boolean.
src/hooks.client.ts Starts the memoized backend bootstrap eagerly during hydration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/routes/(app)/+layout.ts
Comment thread src/lib/state/backend-metadata-state.svelte.ts Outdated
Comment thread src/lib/state/backend-metadata-state.svelte.ts Outdated
Comment thread src/routes/(app)/+layout.svelte Outdated
Comment thread src/routes/(app)/settings/api-tokens/+page.svelte Outdated
Comment thread src/routes/(app)/shockers/logs/[shockerId=guid]/+page.svelte Outdated
hhvrc added 5 commits May 15, 2026 23:35
- backend-metadata-state holds only static info (version, providers, etc)
- auth state derived from userState.self; SignalR connects/disconnects via $effect.root
- 401 responses now clear auth state globally via registerOnUnauthorized
- bootstrap.svelte trimmed; login/logout touch userState directly
- authState tracks Booting/Authenticated/Unauthenticated and owns the
  reactive lifecycle (SignalR connect/disconnect, 401 → reset)
- hooks.client.ts is now the literal entry point; bootstrap.svelte.ts is gone
- (app)/+layout.ts load is sync — SvelteKit awaits hooks init before loads
- login page drops redundant {#await} skeleton; reads providers reactively
- (app)/+layout.svelte safety-net redirect now preserves next= like the
  initial load gate, so mid-session logouts return to the original page
- api-tokens refresh toast only fires on successful reload
- shockers/logs page uses $effect keyed on shockerId so navigating
  between different shocker logs refreshes the data
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comment thread src/routes/(app)/shockers/logs/[shockerId=guid]/+page.svelte Outdated
Comment thread src/routes/(app)/settings/api-tokens/+page.svelte
@hhvrc hhvrc merged commit 0a43128 into develop May 17, 2026
11 checks passed
@hhvrc hhvrc deleted the fix/authed-page-race-condition branch May 17, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants