docs(solid-router): authenticated-routes example #5825
main fromrefs/pull/5825/head·merged by birkskyum(GitHub profile, opens in a new tab) Summary by CodeRabbit#
Release Notes#
New Features
- Added a complete Solid.js authenticated routing example project showcasing login/logout flows, protected routes with authentication guards, dashboard navigation, and invoice management powered by TanStack Router.
Documentation
- Added example project README with setup and run instructions.
- 1
View your CI Pipeline Execution ↗ for commit 5feb7e266f3c8c50fc17c14b61653cfc71cc4b57
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 49s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 3s View ↗
☁️ Nx Cloud last updated this comment at
2025-11-11 23:50:08UTCMore templates
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-example-basic-supabase
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5825@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5825@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5825@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5825@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5825@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5825@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5825@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5825@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5825@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5825@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5825@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5825@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5825@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5825@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5825@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5825@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5825@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5825@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5825@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5825@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5825@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5825@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5825@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5825@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5825@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5825@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5825@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5825@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5825@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5825@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5825@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5825@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5825@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5825@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5825commit:
5feb7e2Actionable comments posted: 4
🧹 Nitpick comments (4)
examples/solid/authenticated-routes/README.md (1)
1-1: Consider a more descriptive heading.The heading "# Example" is generic. Updating it to "# Authenticated Routes Example" or similar would make the purpose of the example immediately clear to readers, aligning with the directory name and example's functionality.
-# Example +# Authenticated Routes Exampleexamples/solid/authenticated-routes/src/posts.tsx (1)
19-19: Consider safer initialization pattern.The non-null assertion (
null!) could lead to runtime errors ifinvoicesis accessed before initialization completes. While the current usage withensureInvoices()appears safe, this is fragile.Consider initializing as:
-let invoices: Array<Invoice> = null! +let invoices: Array<Invoice> | undefined = undefinedThen add a guard in
fetchInvoicesandfetchInvoiceByIdif needed.examples/solid/authenticated-routes/index.html (1)
1-12: Consider updating the title to be more descriptive.The generic "Vite App" title could be more descriptive, e.g., "TanStack Router - Authenticated Routes Example".
Apply this diff:
- <title>Vite App</title> + <title>TanStack Router - Authenticated Routes Example</title>examples/solid/authenticated-routes/src/routes/login.tsx (1)
13-14: Remove unnecessary const assertion.The
as constassertion on a string literal is redundant since TypeScript already infers the exact literal type'/dashboard'. The eslint-disable comment confirms this is unnecessary.-// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -const fallback = '/dashboard' as const +const fallback = '/dashboard'📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between f0e02799ce6c45d5257ad319f010141fecde6116 and 5feb7e266f3c8c50fc17c14b61653cfc71cc4b57.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (22)
examples/solid/authenticated-routes/.gitignore(1 hunks)examples/solid/authenticated-routes/.vscode/settings.json(1 hunks)examples/solid/authenticated-routes/README.md(1 hunks)examples/solid/authenticated-routes/index.html(1 hunks)examples/solid/authenticated-routes/package.json(1 hunks)examples/solid/authenticated-routes/postcss.config.mjs(1 hunks)examples/solid/authenticated-routes/src/auth.tsx(1 hunks)examples/solid/authenticated-routes/src/main.tsx(1 hunks)examples/solid/authenticated-routes/src/posts.tsx(1 hunks)examples/solid/authenticated-routes/src/routeTree.gen.ts(1 hunks)examples/solid/authenticated-routes/src/routes/__root.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/_auth.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/index.tsx(1 hunks)examples/solid/authenticated-routes/src/routes/login.tsx(1 hunks)examples/solid/authenticated-routes/src/styles.css(1 hunks)examples/solid/authenticated-routes/src/utils.ts(1 hunks)examples/solid/authenticated-routes/tsconfig.json(1 hunks)examples/solid/authenticated-routes/vite.config.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
examples/{react,solid}/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep example applications under examples/react/ and examples/solid/
Files:
examples/solid/authenticated-routes/README.mdexamples/solid/authenticated-routes/src/routes/_auth.dashboard.tsxexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/index.htmlexamples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsxexamples/solid/authenticated-routes/src/routes/__root.tsxexamples/solid/authenticated-routes/src/utils.tsexamples/solid/authenticated-routes/src/styles.cssexamples/solid/authenticated-routes/src/routes/login.tsxexamples/solid/authenticated-routes/postcss.config.mjsexamples/solid/authenticated-routes/src/posts.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsxexamples/solid/authenticated-routes/src/routes/_auth.tsxexamples/solid/authenticated-routes/src/main.tsxexamples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsxexamples/solid/authenticated-routes/tsconfig.jsonexamples/solid/authenticated-routes/src/auth.tsxexamples/solid/authenticated-routes/package.jsonexamples/solid/authenticated-routes/vite.config.js
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsxexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsxexamples/solid/authenticated-routes/src/routes/__root.tsxexamples/solid/authenticated-routes/src/utils.tsexamples/solid/authenticated-routes/src/routes/login.tsxexamples/solid/authenticated-routes/src/posts.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsxexamples/solid/authenticated-routes/src/routes/_auth.tsxexamples/solid/authenticated-routes/src/main.tsxexamples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsxexamples/solid/authenticated-routes/src/auth.tsx
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsxexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsxexamples/solid/authenticated-routes/src/routes/__root.tsxexamples/solid/authenticated-routes/src/routes/login.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsxexamples/solid/authenticated-routes/src/routes/_auth.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsx
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
Use workspace:* protocol for internal dependencies in package.json files
Files:
examples/solid/authenticated-routes/package.json
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/Learnt from: FatahChan Repo: TanStack/router PR: 5475 File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0 Timestamp: 2025-10-14T18:59:33.990Z Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
examples/solid/authenticated-routes/.vscode/settings.jsonexamples/solid/authenticated-routes/.gitignoreexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsxexamples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsxexamples/solid/authenticated-routes/tsconfig.json
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
examples/solid/authenticated-routes/.vscode/settings.jsonexamples/solid/authenticated-routes/.gitignoreexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsxexamples/solid/authenticated-routes/tsconfig.json
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/{react-router,solid-router}/** : Implement React and Solid bindings/components only in packages/react-router/ and packages/solid-router/Applied to files:
examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsxexamples/solid/authenticated-routes/.gitignoreexamples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsxexamples/solid/authenticated-routes/src/routes/__root.tsxexamples/solid/authenticated-routes/src/routes/login.tsxexamples/solid/authenticated-routes/src/routes/_auth.tsxexamples/solid/authenticated-routes/src/main.tsxexamples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/src/routes/_auth.invoices.tsxexamples/solid/authenticated-routes/tsconfig.jsonexamples/solid/authenticated-routes/package.jsonexamples/solid/authenticated-routes/vite.config.js
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to **/src/routes/** : Place file-based routes under src/routes/ directoriesApplied to files:
examples/solid/authenticated-routes/src/routes/index.tsxexamples/solid/authenticated-routes/src/routeTree.gen.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
examples/solid/authenticated-routes/src/routes/_auth.tsx
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/{router-cli,router-generator,router-plugin,virtual-file-routes}/** : Keep CLI, generators, bundler plugins, and virtual file routing utilities in their dedicated tooling package directoriesApplied to files:
examples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/package.json
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
examples/solid/authenticated-routes/src/routeTree.gen.tsexamples/solid/authenticated-routes/tsconfig.jsonexamples/solid/authenticated-routes/package.json
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to packages/router-core/** : Keep framework-agnostic core router logic in packages/router-core/Applied to files:
examples/solid/authenticated-routes/src/routeTree.gen.ts
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to **/*.{ts,tsx} : Use TypeScript in strict mode with extensive type safety across the codebaseApplied to files:
examples/solid/authenticated-routes/tsconfig.json
🧬 Code graph analysis (10)
examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx (2)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/auth.tsx (1)
useAuth(57-63)
examples/solid/authenticated-routes/src/routes/index.tsx (6)
examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
Route(5-12)
examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
Route(5-10)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/routes/login.tsx (1)
Route(16-26)
examples/solid/authenticated-routes/src/routes/__root.tsx (1)
Route(10-17)
examples/solid/authenticated-routes/src/routes/_auth.dashboard.tsx (1)
Route(5-7)
examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (3)
examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
Route(5-12)
examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
Route(5-10)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/routes/__root.tsx (1)
examples/solid/authenticated-routes/src/auth.tsx (1)
AuthContext(5-10)
examples/solid/authenticated-routes/src/routes/login.tsx (3)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/auth.tsx (1)
useAuth(57-63)
examples/solid/authenticated-routes/src/utils.ts (1)
sleep(1-3)
examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (4)
examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (1)
Route(5-10)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)
Route(3-5)
examples/solid/authenticated-routes/src/posts.tsx (1)
fetchInvoiceById(40-50)
examples/solid/authenticated-routes/src/routes/_auth.tsx (2)
examples/solid/authenticated-routes/src/routes/login.tsx (1)
Route(16-26)
examples/solid/authenticated-routes/src/auth.tsx (1)
useAuth(57-63)
examples/solid/authenticated-routes/src/main.tsx (1)
examples/solid/authenticated-routes/src/auth.tsx (2)
useAuth(57-63)AuthProvider(28-55)
examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (4)
examples/solid/authenticated-routes/src/routes/_auth.invoices.$invoiceId.tsx (1)
Route(5-12)
examples/solid/authenticated-routes/src/routes/_auth.tsx (1)
Route(11-23)
examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)
Route(3-5)
examples/solid/authenticated-routes/src/posts.tsx (1)
fetchInvoices(36-38)
examples/solid/authenticated-routes/src/auth.tsx (1)
examples/solid/authenticated-routes/src/utils.ts (1)
sleep(1-3)
🔇 Additional comments (21)
examples/solid/authenticated-routes/tsconfig.json (1)
1-12: TypeScript configuration is properly set up for Solid.js.The configuration correctly enables strict mode, preserves JSX for Solid's compiler, and targets modern JavaScript with appropriate library definitions. All settings align with TanStack Router's TypeScript standards and Solid.js requirements.
examples/solid/authenticated-routes/.gitignore (1)
1-5: LGTM! Standard and appropriate .gitignore entries.The file includes all necessary exclusions for a Solid.js + Vite project: dependencies, build outputs, OS-specific files, and local config. The ordering is logical and the patterns are correct.
examples/solid/authenticated-routes/vite.config.js (1)
1-14: LGTM! Clean Vite configuration for Solid.js with TanStack Router.The configuration is well-structured:
- Plugin order is correct (TanStack Router plugin before Solid plugin ensures route files are transformed first)
autoCodeSplitting: trueis a good default for examples, demonstrating best practices- Minimal and focused, appropriate for an example project
examples/solid/authenticated-routes/.vscode/settings.json (1)
1-11: LGTM!The VSCode settings appropriately handle the autogenerated
routeTree.gen.tsfile by excluding it from watchers/search and marking it as readonly to prevent accidental modifications.examples/solid/authenticated-routes/src/utils.ts (1)
1-3: LGTM!The
sleeputility function is correctly implemented for introducing asynchronous delays.examples/solid/authenticated-routes/postcss.config.mjs (1)
1-5: LGTM!Standard PostCSS configuration for Tailwind CSS v4 integration.
examples/solid/authenticated-routes/src/posts.tsx (2)
23-34: LGTM!The lazy initialization pattern with shared promise prevents duplicate fetches and handles concurrent access correctly.
36-50: LGTM!The exported functions correctly apply the loader delay and handle the invoice not found case with an appropriate error.
examples/solid/authenticated-routes/src/styles.css (1)
1-21: LGTM!The Tailwind CSS v4 syntax is correctly used with the new
@import 'tailwindcss'directive,@layer,@apply, and standard utility classes.examples/solid/authenticated-routes/src/routes/_auth.invoices.index.tsx (1)
1-5: LGTM!The index route correctly provides a placeholder message when no invoice is selected. The route definition follows TanStack Router conventions and appropriately relies on the parent route's loader for data.
examples/solid/authenticated-routes/src/routes/_auth.invoices.tsx (2)
5-10: LGTM!The route definition correctly uses the loader pattern to fetch invoices asynchronously and the structure follows TanStack Router conventions.
12-42: LGTM!The component correctly accesses loader data via signal accessor, implements a responsive layout using Tailwind CSS v4, and properly sets up nested routing with the Outlet. The invoice list rendering and link navigation are well-structured.
examples/solid/authenticated-routes/src/auth.tsx (4)
5-10: LGTM!The AuthContext interface is well-defined with appropriate method signatures for authentication operations.
12-14: LGTM!The context initialization with null default is appropriate given the useAuth hook enforces usage within the provider.
16-26: LGTM!The storage helper functions correctly handle reading and writing user data to localStorage, including proper cleanup when user is null.
57-63: LGTM!The useAuth hook correctly enforces usage within the AuthProvider with a clear error message.
examples/solid/authenticated-routes/src/routes/login.tsx (2)
16-26: LGTM!The route definition correctly validates the search params with Zod, implements a beforeLoad guard to redirect authenticated users, and follows TanStack Router conventions.
28-97: LGTM!The login component correctly handles form submission, authentication flow, and navigation. The acknowledged
sleep(1)hack on line 52 is acceptable for an example application demonstrating authentication patterns.examples/solid/authenticated-routes/src/routes/_auth.tsx (2)
11-23: LGTM!The beforeLoad guard correctly implements authentication checking and redirects unauthenticated users to the login page while preserving the intended destination.
25-71: LGTM!The AuthLayout component correctly implements the logout flow with user confirmation and proper promise chaining. The navigation structure and Outlet placement are appropriate for the authenticated route layout.
examples/solid/authenticated-routes/src/routeTree.gen.ts (1)
1-195: Skipping review of generated file.This file is autogenerated by TanStack Router and should not be manually modified or reviewed. Based on learnings.
examples/solid/authenticated-routes/package.json lines 13 to 15@@ -0,0 +1,15 @@1+{2+ "name": "tanstack-router-solid-example-authenticated-routes",3+ "private": true,4+ "type": "module",5+ "scripts": {6+ "dev": "vite --port 3000",7+ "build": "vite build && tsc --noEmit",8+ "serve": "vite preview",9+ "start": "vite"10+ },11+ "dependencies": {12+ "@tailwindcss/postcss": "^4.1.15",13+ "@tanstack/solid-router": "^1.135.2",14+ "@tanstack/solid-router-devtools": "^1.135.2",15+ "@tanstack/router-plugin": "^1.135.2",⚠️ Potential issue | 🟠 Major
Use
workspace:*protocol for internal TanStack dependencies.Internal monorepo dependencies should use the
workspace:*protocol instead of version ranges to ensure proper monorepo dependency resolution.As per coding guidelines.
Apply this diff:
- "@tanstack/solid-router": "^1.135.2", - "@tanstack/solid-router-devtools": "^1.135.2", - "@tanstack/router-plugin": "^1.135.2", + "@tanstack/solid-router": "workspace:*", + "@tanstack/solid-router-devtools": "workspace:*", + "@tanstack/router-plugin": "workspace:*",📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"@tanstack/solid-router": "workspace:*", "@tanstack/solid-router-devtools": "workspace:*", "@tanstack/router-plugin": "workspace:*",🤖 Prompt for AI Agents
In examples/solid/authenticated-routes/package.json around lines 13 to 15 the internal TanStack dependencies use version ranges; replace the version ranges for "@tanstack/solid-router", "@tanstack/solid-router-devtools", and "@tanstack/router-plugin" with the workspace:* protocol so they read as workspace:* to ensure monorepo dependency resolution per guidelines.examples/solid/authenticated-routes/src/auth.tsx lines 46 to 48@@ -0,0 +28,21 @@28+export function AuthProvider(props: { children: Solid.JSX.Element }) {29+ const [user, setUser] = Solid.createSignal<string | null>(getStoredUser())30+ const isAuthenticated = () => !!user()31+32+ const logout = async () => {33+ await sleep(250)34+35+ setStoredUser(null)36+ setUser(null)37+ }38+39+ const login = async (username: string) => {40+ await sleep(500)41+42+ setStoredUser(username)43+ setUser(username)44+ }45+46+ Solid.createEffect(() => {47+ setUser(getStoredUser())48+ })⚠️ Potential issue | 🟡 Minor
Remove or properly implement the createEffect for storage synchronization.
This effect runs on every render cycle and redundantly reads from localStorage without any dependencies. The initial user state is already correctly initialized from storage on line 29.
If the intent is to synchronize authentication state across browser tabs, implement a proper storage event listener instead:
- Solid.createEffect(() => { - setUser(getStoredUser()) - }) + Solid.onMount(() => { + const handleStorageChange = (e: StorageEvent) => { + if (e.key === key) { + setUser(e.newValue) + } + } + window.addEventListener('storage', handleStorageChange) + Solid.onCleanup(() => window.removeEventListener('storage', handleStorageChange)) + })Alternatively, if cross-tab sync is not needed, simply remove the effect.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In examples/solid/authenticated-routes/src/auth.tsx around lines 46 to 48, the Solid.createEffect currently reads localStorage on every render; remove this effect or replace it with a single-run mount handler that either (a) removes the Solid.createEffect entirely since initial state is already set from storage on line 29, or (b) implements proper cross-tab sync by adding a window.addEventListener('storage', ...) on mount that checks the auth key, calls setUser(getStoredUser()) when that key changes, and removes the listener on cleanup so it only runs in response to storage events rather than every render.examples/solid/authenticated-routes/src/posts.tsx lines 3 to 11@@ -0,0 +1,11 @@1+import axios from 'redaxios'2+3+async function loaderDelayFn<T>(fn: (...args: Array<any>) => Promise<T> | T) {4+ const delay = Number(sessionStorage.getItem('loaderDelay') ?? 0)5+ const delayPromise = new Promise((r) => setTimeout(r, delay))6+7+ await delayPromise8+ const res = await fn()9+10+ return res11+}⚠️ Potential issue | 🟡 Minor
Fix the
loaderDelayFnparameter signature.The function signature declares
fn: (...args: Array<any>)suggesting it accepts arguments, but Line 8 callsfn()without passing any arguments. This is misleading and could cause issues if a function expecting parameters is passed in.Apply this diff to fix the signature:
-async function loaderDelayFn<T>(fn: (...args: Array<any>) => Promise<T> | T) { +async function loaderDelayFn<T>(fn: () => Promise<T> | T) {📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function loaderDelayFn<T>(fn: () => Promise<T> | T) { const delay = Number(sessionStorage.getItem('loaderDelay') ?? 0) const delayPromise = new Promise((r) => setTimeout(r, delay)) await delayPromise const res = await fn() return res }🤖 Prompt for AI Agents
In examples/solid/authenticated-routes/src/posts.tsx around lines 3 to 11, the loaderDelayFn parameter is typed as fn: (...args: Array<any>) which implies it expects arguments but the implementation always calls fn() with no args; change the parameter signature to fn: () => Promise<T> | T so it correctly represents a no-argument callback (update the type only, leaving the call site as fn()).examples/solid/authenticated-routes/src/routes/index.tsx lines 33 to 39@@ -0,0 +19,21 @@19+ adapt then to work with your authentication flow/system for your app.20+ </p>21+ <p>22+ You are currently on the index route of the{' '}23+ <strong>authenticated-routes</strong> example.24+ </p>25+ <p>You can try going through these options.</p>26+ <ol class="list-disc list-inside px-2">27+ <li>28+ <Link to="/login" class="text-blue-500 hover:opacity-75">29+ Go to the public login page.30+ </Link>31+ </li>32+ <li>33+ <Link to="/dashboard" class="text-blue-500 hover:opacity-75">34+ Go to the auth-only dashboard page.35+ </Link>36+ </li>37+ <li>38+ <Link to="/invoices" class="text-blue-500 hover:opacity-75">39+ Go to the auth-only invoices page.⚠️ Potential issue | 🔴 Critical
Fix dashboard/invoices link targets.
These links point to
/dashboardand/invoices, but the only registered routes are/_auth/dashboardand/_auth/invoices. Clicking them currently lands on an undefined route, so users never reach the protected pages or their guards. Update thetovalues to the actual paths.- <Link to="/dashboard" class="text-blue-500 hover:opacity-75"> + <Link to="/_auth/dashboard" class="text-blue-500 hover:opacity-75"> Go to the auth-only dashboard page. </Link> </li> <li> - <Link to="/invoices" class="text-blue-500 hover:opacity-75"> + <Link to="/_auth/invoices" class="text-blue-500 hover:opacity-75"> Go to the auth-only invoices page. </Link>📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<Link to="/_auth/dashboard" class="text-blue-500 hover:opacity-75"> Go to the auth-only dashboard page. </Link> </li> <li> <Link to="/_auth/invoices" class="text-blue-500 hover:opacity-75"> Go to the auth-only invoices page.🤖 Prompt for AI Agents
In examples/solid/authenticated-routes/src/routes/index.tsx around lines 33 to 39, the Link components point to /dashboard and /invoices but the app registers routes at /_auth/dashboard and /_auth/invoices; update the Link `to` props to use the actual registered paths /_auth/dashboard and /_auth/invoices so clicks navigate to the protected pages and their guards.birkskyum(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Adds a complete authenticated routes example for Solid.js using TanStack Router, featuring authentication context, protected routes with beforeLoad guards, data loading, login/redirect flows, and Tailwind CSS styling.
Changes#
.gitignore,tsconfig.json,vite.config.js,postcss.config.mjs,package.json.vscode/settings.json,README.md,index.htmlsrc/auth.tsx,src/main.tsx,src/utils.tssrc/posts.tsxsrc/routes/__root.tsx,src/routes/index.tsx,src/routes/login.tsx,src/routes/_auth.tsx,src/routes/_auth.dashboard.tsx,src/routes/_auth.invoices.tsx,src/routes/_auth.invoices.index.tsx,src/routes/_auth.invoices.$invoiceId.tsx,src/routeTree.gen.tssrc/styles.cssSequence Diagram#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
src/auth.tsx— AuthContext implementation, storage persistence, and login/logout logicsrc/routes/_auth.tsx— beforeLoad guard, logout handler, and navigation flowsrc/routes/_auth.invoices.$invoiceId.tsx— loader function and error handling for invoice fetchingsrc/routeTree.gen.ts— verify generated route tree structure, parent-child relationships, and type exports_auth.,$invoiceIddynamic segmentsPossibly related PRs#
Suggested labels#
documentation,package: solid-routerSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share