fix: Authenticated page race condition#198
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.tsthat awaits a memoized backend/user bootstrap and redirects unauthenticated users to/login?next=.... - Consolidate backend bootstrap (backend metadata fetch +
userState.refreshSelf()+ SignalR init) intobackendMetadata.init()and invoke it during hydration. - Replace
+page.tsloads for shocker log pages withonMount-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.
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.