Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

README.md

51 lines1.3 KB

1# TanStack Start - Basic Auth Example
2​
3A TanStack Start example demonstrating authentication patterns and protected routes.
4​
5- [TanStack Router Docs](https://tanstack.com/router)
6​
7## Start a new project based on this example
8​
9To start a new project based on this example, run:
10​
11```sh
12npx gitpick TanStack/router/tree/main/examples/react/start-basic-auth start-basic-auth
13```
14​
15## Getting Started
16​
17From your terminal:
18​
19```sh
20pnpm install
21pnpm dev
22```
23​
24This starts your app in development mode, rebuilding assets on file changes.
25​
26## Build
27​
28To build the app for production:
29​
30```sh
31pnpm build
32```
33​
34## Authentication Features
35​
36This example demonstrates:
37​
38- User authentication flow
39- Protected routes
40- Login/logout functionality
41- Redirect after authentication
42​
43## Session configuration
44​
45This example uses [iron-session](https://github.com/vvo/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:
46​
47```sh
48export SESSION_PASSWORD="$(openssl rand -base64 32)"
49```
50​
51Keep 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.