0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/examples/react/start-basic-auth
github-actions[bot] ed86c440c5
ci: Version Packages (#8891)
ci: changeset release

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
History 2026-11-08 10:47:39 +01:00
..
.devcontainer docs: add devcontainer.json to all e2e/examples (#6972) 2026-03-18 15:43:14 +01:00
.vscode chore(examples): add .vscode/settings.json configuration (#3349) 2025-02-07 10:29:48 +13:00
prisma update start-basic-auth project to prisma 7 (#5911) 2025-11-20 19:44:02 +01:00
public feat(react-router): add context option to route (#2104) 2024-08-20 13:39:17 -06:00
src response reconciliation (#7588) 2026-10-13 00:01:04 +02:00
.env feat(react-router): add context option to route (#2104) 2024-08-20 13:39:17 -06:00
.gitignore feat: Merge alpha to main (#4365) 2025-06-10 23:19:32 +02:00
.prettierignore chore(examples): cleanup the deps for the start examples (#2388) 2024-09-21 22:21:59 +12:00
dev.db update start-basic-auth project to prisma 7 (#5911) 2025-11-20 19:44:02 +01:00
package.json ci: Version Packages (#8891) 2026-11-08 10:47:39 +01:00
prisma.config.ts update start-basic-auth project to prisma 7 (#5911) 2025-11-20 19:44:02 +01:00
README.md response reconciliation (#7588) 2026-10-13 00:01:04 +02:00
tsconfig.json chore: upgrade tooling to typescript 6 (#7024) 2026-03-23 22:59:52 +01:00
vite.config.ts docs: update examples/e2e to vite 8 (#6958) 2026-03-17 20:37:11 +01:00

TanStack Start - Basic Auth Example

A TanStack Start example demonstrating authentication patterns and protected routes.

Start a new project based on this example

To start a new project based on this example, run:

npx gitpick TanStack/router/tree/main/examples/react/start-basic-auth start-basic-auth

Getting Started

From your terminal:

pnpm install
pnpm dev

This starts your app in development mode, rebuilding assets on file changes.

Build

To build the app for production:

pnpm build

Authentication Features

This example demonstrates:

  • User authentication flow
  • Protected routes
  • Login/logout functionality
  • Redirect after authentication

Session configuration

This example uses iron-session through Start's getCookie and setCookie helpers. Set SESSION_PASSWORD to a random secret of at least 32 characters before starting the app, for example:

export SESSION_PASSWORD="$(openssl rand -base64 32)"

Keep the same secret across instances and deployments that must read the same sessions. The cookie requires HTTPS in production. Each handler reads its own session, then awaits session.save() before redirecting or returning.