> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bijection & WorkOS AuthKit

[WorkOS AuthKit](https://authkit.com) is an authentication solution that enables
sign-in using passwords, social login providers, email one-time codes,
two-factor authentication, and user management capabilities.

You can use your own WorkOS account with AuthKit or let Bijection create a managed
WorkOS team which enables provisioning and configuration of AuthKit environments
automatically.

The docs below are targeted at starting a new project with WorkOS AuthKit and
Bijection. If you have an existing app that you'd like to migrate, see the
[Add to Existing App](https://docs.bijection.com/access/authentication/providers/authkit/existing-app.md) instructions instead.

## Get started

[Install the Bijection CLI](https://docs.bijection.com/start/install.md), then create a starter:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection create my-app
```

The default React (Vite) workspace includes its frontend adapter, authentication
configuration and protected backend example. Run `bijection dev` to configure the
backend and start the app. Development registers each assigned app origin and
`/callback` URL. Managed publication binds the target's public AuthKit client ID
and configures its assigned origins before activation. Provider secrets remain in
the target's private environment.

For an existing app, follow [Add to Existing App](https://docs.bijection.com/access/authentication/providers/authkit/existing-app.md),
then run `bijection dev`.

The [private notes example](https://github.com/bijectionhq/bijection/tree/main/examples/authentication-authkit)
shows how to use AuthKit with a label and a scoped grant for each signed-in author.
For email-bound invitations, use the shared
[verified email setting](https://docs.bijection.com/access/authentication#trust-verified-email-for-invitations).

To connect WorkOS, follow the instructions in one of the sections below.

## Option 1: use a Bijection-managed WorkOS team&#x20;

> [!TIP]
>
> Choose this option if you're new to WorkOS or want Bijection to create a
> WorkOS environment for each of your installations.

A Bijection team Admin can create the managed WorkOS team. Developers and
Admins can create the WorkOS environment for a deployment they can deploy to.

Provision the environment with `bijection installation workos provision` and
read the public client ID with `bijection installation workos status`. Add
that ID to the tree's `issuer.authkit` declaration. The deployment's WorkOS
API key remains with the managed installation. Configure the frontend
origin, redirects and CORS in WorkOS.

If the management service reports that managed authentication is unavailable,
[configure an existing WorkOS team](https://docs.bijection.com/access/authentication/providers/authkit#option-2-use-an-existing-workos-team).

> [accordion] What if I already have a WorkOS account?
>
> A managed team is a new WorkOS team whose administrator is the verified email
> you signed in with. If WorkOS already has an account for that email, or it
> administers another Bijection team's managed WorkOS team, `provision-team`
> can't create the team; follow
> [Option 2](https://docs.bijection.com/access/authentication/providers/authkit#option-2-use-an-existing-workos-team) instead. With your existing team,
> Bijection doesn't create WorkOS environments for your installations: you create
> them in WorkOS and set their credentials yourself.

## Option 2: use an existing WorkOS team&#x20;

> [!TIP]
>
> Choose this option if you're an established WorkOS AuthKit user and using your
> existing WorkOS team is more important than having Bijection create a WorkOS
> environment for each deployment.

Configure your Bijection
deployment and client framework yourself.

**1. Find your WorkOS Client ID and API Key**

From the WorkOS dashboard [get started](https://dashboard.workos.com/get-started) page under **Quick start**, find your
`WORKOS_CLIENT_ID` and `WORKOS_API_KEY`.

**2. Set the values in your installation**

Use the `bijection` CLI to set environment variables for `WORKOS_CLIENT_ID`
and `WORKOS_API_KEY` with values from the WorkOS dashboard in the previous step.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection env set WORKOS_CLIENT_ID $YOUR_CLIENT_ID_HERE
bijection env set WORKOS_API_KEY $YOUR_API_KEY_HERE
```

**3. Deploy your application**

Run `bijection dev` to automatically sync your configuration to your backend.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection dev
```

> [!NOTE]
>
> For multiple Bijection applications integrated with an existing WorkOS team
> you'll need to decide if the [single-tenant or multi-tenant
> model](https://workos.com/docs/authkit/modeling-your-app/single-tenant-and-multi-tenant-models)
> is right for your situation. That may include manually provisioning additional
> WorkOS environments.

## Next steps

### Accessing user information in functions

See [Auth in Functions](https://docs.bijection.com/access/authentication/functions.md) to learn about how to access
information about the authenticated user in your queries and mutations.

See [Storing Users in the Bijection Database](https://docs.bijection.com/access/authentication/user-records.md) to learn
about how to store user information in the Bijection database.

### Accessing user information client-side

To access the authenticated user's information, use AuthKit's `User` object,
which can be accessed using AuthKit's
[`useAuth()`](https://github.com/workos/authkit-react?tab=readme-ov-file#useauth)
hook. For more information on the `User` object, see the
[WorkOS docs](https://workos.com/docs/reference/user-management/user).

```tsx components/Badge.tsx theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { useAuth } from "@workos-inc/authkit-react";

export default function Badge() {
  const { user } = useAuth();
  return user === null ? null : <span>Signed in as {user.firstName}</span>;
}
```

## Configuring dev and prod instances

To configure a different AuthKit instance between your Bijection development and
production deployments, you can use environment variables configured on the
Bijection console and referenced in `bijection/sign-in.ts`.

As long as you started from `bijection create` or the instructions for
[adding AuthKit to an existing Bijection app](https://docs.bijection.com/access/authentication/providers/authkit/existing-app.md), your
`bijection/sign-in.ts` file will make use of the `WORKOS_CLIENT_ID` value
referenced below.

> [accordion] Sample issuer declaration
>
> ```ts bijection/sign-in.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> import { issuer } from "@bijectionhq/bijection";
>
> // The client ID is an installation value: `bijection issuer trust signIn --client-id client_…`.
> export const signIn = issuer.authkit({});
> ```

**Development configuration**

In the deployment switcher at the top of the Bijection
[console](https://console.bijection.com), switch to your development deployment
and set the `WORKOS_CLIENT_ID` environment variable to your development WorkOS
Client ID.

Put the same public client ID in a JSON file as
`{"WORKOS_CLIENT_ID":"client_…"}`. Run
`bijection check --write-lock --definition-inputs public-inputs.json`, review the
issuer entries, then run `bijection dev`.

**Production configuration**

In the deployment switcher at the top of the Bijection
[console](https://console.bijection.com), switch to your production deployment
and set the `WORKOS_CLIENT_ID` environment variable to your production WorkOS
Client ID.

Include both client IDs in the allowed `oneOf` set and derive the lock with the production client ID using the same
`bijection check --write-lock --definition-inputs public-inputs.json` workflow. Deploy the reviewed
lock with `bijection deploy`. The running installation switches issuers when the
deploy activates.

### Configuring WorkOS AuthKit's API keys

WorkOS AuthKit's API keys differ depending on whether they are for development
or production. Don't forget to update the environment variables in your `.env`
file as well as your hosting platform, such as Vercel or Netlify.

**Development configuration**

WorkOS API Key for development follows the format `sk_test_...`. WorkOS Client
ID for development follows the format `client_01...`.

```env .env.local theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
WORKOS_CLIENT_ID="client_01XXXXXXXXXXXXXXXXXXXXXXXX"
WORKOS_API_KEY="sk_test_..."
WORKOS_COOKIE_PASSWORD="your_secure_password_here_must_be_at_least_32_characters_long"
NEXT_PUBLIC_WORKOS_REDIRECT_URI="http://localhost:3000/callback"
```

**Production configuration**

WorkOS API Key for production follows the format `sk_live_...`. WorkOS Client ID
for production follows the format `client_01...`.

```env .env theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
WORKOS_CLIENT_ID="client_01XXXXXXXXXXXXXXXXXXXXXXXX"
WORKOS_API_KEY="sk_live_..."
WORKOS_COOKIE_PASSWORD="your_secure_password_here_must_be_at_least_32_characters_long"
NEXT_PUBLIC_WORKOS_REDIRECT_URI="https://your-domain.com/callback"
```

## Under the hood

Your identity provider issues the application token. The frontend's auth
adapter (`authkit()`, `clerk()` or `bijectionAuth()` from
`@bijectionhq/bijection/client`) hands it to the client made with
`connect(url, { token: auth })`, which asks for the current token
on every request and live connection. The deployment verifies the token
against `bijection/sign-in.ts` before admitting a call. The roles the
caller holds, the labels they clear and the app's guards then decide what the
call may do.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.