|
16 | 16 | yarn add @workos-inc/authkit-remix
|
17 | 17 | ```
|
18 | 18 |
|
19 |
| -## Pre-flight |
| 19 | +## Configuration |
20 | 20 |
|
21 |
| -Make sure the following values are present in your `.env.local` environment variables file. The client ID and API key can be found in the [WorkOS dashboard](https://dashboard.workos.com), and the redirect URI can also be configured there. |
| 21 | +AuthKit for Remix offers a flexible configuration system that allows you to customize various settings. You can configure the library in three ways: |
22 | 22 |
|
23 |
| -```sh |
24 |
| -WORKOS_CLIENT_ID="client_..." # retrieved from the WorkOS dashboard |
25 |
| -WORKOS_API_KEY="sk_test_..." # retrieved from the WorkOS dashboard |
26 |
| -WORKOS_REDIRECT_URI="http://localhost:5173/callback" # configured in the WorkOS dashboard |
27 |
| -WORKOS_COOKIE_PASSWORD="<your password>" # generate a secure password here |
28 |
| -``` |
| 23 | +### 1. Environment Variables |
29 | 24 |
|
30 |
| -`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: |
| 25 | + The simplest way is to set environment variables in your `.env.local` file: |
31 | 26 |
|
| 27 | + ```bash |
| 28 | + WORKOS_CLIENT_ID="client_..." # retrieved from the WorkOS dashboard |
| 29 | + WORKOS_API_KEY="sk_test_..." # retrieved from the WorkOS dashboard |
| 30 | + WORKOS_REDIRECT_URI="http://localhost:5173/callback" # configured in the WorkOS dashboard |
| 31 | + WORKOS_COOKIE_PASSWORD="<your password>" # generate a secure password here |
32 | 32 | ```
|
33 |
| -openssl rand -base64 24 |
| 33 | + |
| 34 | +### 2. Programmatic Configuration |
| 35 | + |
| 36 | +You can also configure AuthKit programmatically by importing the `configure` function: |
| 37 | + |
| 38 | +```typescript |
| 39 | +import { configure } from '@workos-inc/authkit-remix'; |
| 40 | +// In your root or entry file |
| 41 | +configure({ |
| 42 | + clientId: 'client_1234567890', |
| 43 | + apiKey: 'sk_test_1234567890', |
| 44 | + redirectUri: 'http://localhost:5173/callback', |
| 45 | + cookiePassword: 'your-secure-cookie-password', |
| 46 | + // Optional settings |
| 47 | + cookieName: 'my-custom-cookie-name', |
| 48 | + apiHttps: true, |
| 49 | + cookieMaxAge: 60 * 60 * 24 * 30, // 30 days |
| 50 | +}); |
34 | 51 | ```
|
35 | 52 |
|
36 |
| -To use the `signOut` method, you'll need to set your app's homepage in your WorkOS dashboard settings under "Redirects". |
| 53 | +### 3. Custom Environment Source |
37 | 54 |
|
38 |
| -### Optional configuration |
| 55 | +For non-standard environments (like Deno or Edge functions), you can provide a custom environment variable source: |
39 | 56 |
|
40 |
| -Certain environment variables are optional and can be used to debug or configure cookie settings. |
| 57 | +> [!Warning] |
| 58 | +> |
| 59 | +>While this library includes support for custom environment sources that could theoretically work in non-Node.js runtimes like Deno or Edge functions, this functionality has not been extensively tested (yet). If you're planning to use AuthKit in these environments, you may encounter unexpected issues. We welcome feedback and contributions from users who test in these environments. |
41 | 60 |
|
42 |
| -```sh |
43 |
| -WORKOS_COOKIE_MAX_AGE='600' # maximum age of the cookie in seconds. Defaults to 400 days |
44 |
| -WORKOS_API_HOSTNAME='api.workos.com' # base WorkOS API URL |
45 |
| -WORKOS_API_HTTPS=true # whether to use HTTPS in API calls |
46 |
| -WORKOS_API_PORT=5173 # port to use for API calls |
| 61 | +```typescript |
| 62 | +import { configure } from '@workos-inc/authkit-remix'; |
| 63 | + |
| 64 | +configure(key => Deno.env.get(key)); |
| 65 | +// Or combine with explicit values |
| 66 | +configure( |
| 67 | + { clientId: 'client_1234567890' }, |
| 68 | + key => Deno.env.get(key) |
| 69 | +); |
47 | 70 | ```
|
48 | 71 |
|
| 72 | +### Configuration Priority |
| 73 | + |
| 74 | +When retrieving configuration values, AuthKit follows this priority order: |
| 75 | + |
| 76 | +1. Programmatically provided values via `configure()` |
| 77 | +2. Environment variables (prefixed with `WORKOS_`) |
| 78 | +3. Default values for optional settings |
| 79 | + |
| 80 | +### Available Configuration Options |
| 81 | + |
| 82 | +>[!NOTE] |
| 83 | +> |
| 84 | +>To print out the entire config, a `getFullConfig` function is provided for debugging purposes. |
| 85 | +
|
| 86 | +| Option | Environment Variable | Default | Required | Description | |
| 87 | +| ---- | ---- | ---- | ---- | ---- | |
| 88 | +| `clientId` | `WORKOS_CLIENT_ID` | - | Yes | Your WorkOS Client ID | |
| 89 | +| `apiKey` | `WORKOS_API_KEY` | - | Yes | Your WorkOS API Key | |
| 90 | +| `redirectUri` | `WORKOS_REDIRECT_URI` | - | Yes | The callback URL configured in WorkOS | |
| 91 | +| `cookiePassword` | `WORKOS_COOKIE_PASSWORD` | - | Yes | Password for cookie encryption (min 32 chars) | |
| 92 | +| `cookieName` | `WORKOS_COOKIE_NAME` | `wos-session` | No | Name of the session cookie | |
| 93 | +| `apiHttps` | `WORKOS_API_HTTPS` | `true` | No | Whether to use HTTPS for API calls | |
| 94 | +| `cookieMaxAge` | `WORKOS_COOKIE_MAX_AGE` | `34560000` (400 days) | No | Maximum age of cookie in seconds | |
| 95 | +| `apiHostname` | `WORKOS_API_HOSTNAME` | `api.workos.com` | No | WorkOS API hostname | |
| 96 | +| `apiPort` | `WORKOS_API_PORT` | - | No | Port to use for API calls | |
| 97 | + |
| 98 | +>[!NOTE] |
| 99 | +> |
| 100 | +>The `cookiePassword` must be at least 32 characters long for security reasons. |
| 101 | +
|
49 | 102 | ## Setup
|
50 | 103 |
|
51 | 104 | ### Callback route
|
|
0 commit comments