Open History to see the last commit
1# TanStack Start + WorkOS
2β
3This site is built with TanStack Router! An example application demonstrating how to authenticate users with AuthKit and the WorkOS Node SDK.
4β
5- [TanStack Router Docs](https://tanstack.com/router)
6- [WorkOS Documentation](https://workos.com/docs)
7β
8## Start a new project based on this example
9β
10To start a new project based on this example, run:
11β
12```sh
13npx gitpick TanStack/router/tree/main/examples/react/start-workos start-workos
14```
15β
16## Prerequisites
17β
18You will need a [WorkOS account](https://dashboard.workos.com/signup).
19β
20## Running the example
21β
221. In the [WorkOS dashboard](https://dashboard.workos.com), click on the User Management tile and set up the [sign-in callback redirect](https://workos.com/docs/user-management/1-configure-your-project/configure-a-redirect-uri) as `http://localhost:3000/api/auth/callback`. Once completed, set the app homepage URL to `http://localhost:3000`.
23 > [!NOTE]
24 > If you already have set up an application in your WorkOS dashboard, then you can simply head to the _Redirects_ tab and add a new redirect URI.
252. After creating the redirect URI, navigate to the API keys tab and copy the _Client ID_ and the _Secret Key_. Rename the `.env.example` file to `.env` and supply your Client ID and API key as environment variables.
263. Additionally, create a cookie password as the private key used to encrypt the session cookie. Copy the output into the environment variable `WORKOS_COOKIE_PASSWORD`.
27 It has to be at least 32 characters long. You can use https://1password.com/password-generator/ to generate strong passwords.
284. Verify your `.env.local` file has the following variables filled.
29 ```bash
30 WORKOS_CLIENT_ID=<YOUR_CLIENT_ID>
31 WORKOS_API_KEY=<YOUR_API_SECRET_KEY>
32 WORKOS_COOKIE_PASSWORD=<YOUR_COOKIE_PASSWORD>
33 WORKOS_REDIRECT_URI=http://localhost:3000/api/auth/callback
34 ```
35 `WORKOS_COOKIE_PASSWORD` is the private key used to encrypt the session cookie. It has to be at least 32 characters long. You can use the [1Password generator](https://1password.com/password-generator/) or the `openssl` library to generate a strong password via the command line:
36 ```bash
37 openssl rand -base64 24
38 ```
39 To use the `signOut` method, you'll need to set a default Logout URI in your WorkOS dashboard settings under "Redirects".
405. Run the following command and navigate to [http://localhost:3000](http://localhost:3000).
41 ```bash
42 pnpm dev
43 ```
44β
45## Build
46β
47Build for production:
48β
49```sh
50pnpm build
51```
52β
53## About This Example
54β
55This example demonstrates:
56β
57- WorkOS authentication integration
58- AuthKit usage
59- Protected routes
60- User session management