Project configuration
The first step to getting your app up and running with WorkOS AuthKit is getting your Bijection project properly configured. Most users should opt for using a Managed WorkOS team where Bijection provisions and automatically configures WorkOS environments for projects and deployments. If you have an existing WorkOS team and account that you want to use with your Bijection application then you should follow the Standard WorkOS team instructions.Setting up the Managed WorkOS team and inviting members to it require team
admin. Per-deployment WorkOS environments use the deployment’s own
management permission, so any team member can provision one for their
dev/preview deployment, while prod envs and shared project-level envs require
team admin or project admin.
- Managed WorkOS team
- Standard WorkOS team
1
Create or update bijection.json
You’ll need a
bijection.json file in the root of your project with contents that match your framework.
You can find more details about the authKit section of bijection.json in the
Automatic Config docs.If you don’t see an example for your framework, consult its documentation for details
about how to specify environment variables and which ports it uses for development servers and
alter one of the examples accordingly.Take care to not expose your WORKOS_API_KEY in a public environment variable. On the other hand,
the WORKOS_CLIENT_ID is safe to include in your client bundle.- React (Vite)
- Next.js
- TanStack Start
2
Create or update auth.config.ts
In your app’s
bijection/ folder, create or update the auth.config.ts
file with the following code. This is the server-side configuration for validating access tokens.bijection/auth.config.ts
3
Deploy your configuration to your dev environment
During deployment, you will be prompted to create a new Bijection-managed WorkOS
team or an existing one will be detected and used. Bijection will then provision
a new environment for your application in your WorkOS team.
Client configuration
Bijection offers a provider that is specifically for integrating with WorkOS AuthKit called<BijectionProviderWithAuthKit>. It works using WorkOS’s
authkit-react SDK.
Once you’ve completed the WorkOS setup above, choose your framework below to
continue with the integration.
See the following sections for the WorkOS SDK that you’re using.
- React
- Next.js
- TanStack Start
Example:
React with Bijection and AuthKitThis guide assumes you have AuthKit set up and have a
working React app with Bijection. If not follow the
Bijection React Quickstart first. Then:Note: The
React template
includes additional features and functions for a complete working application.
This tutorial covers the core integration steps, but the template provides a
more comprehensive implementation.
1
Set up CORS in the WorkOS Dashboard
In your WorkOS Dashboard, go to Authentication > Sessions > Cross-Origin Resource Sharing (CORS) and click on Manage. Add your local development domain (e.g.,
http://localhost:5173 for Vite) to the list. You’ll also need to add your production domain when you deploy. This enables your application to authenticate users through WorkOS AuthKit.2
Set up your environment variables
In your
.env.local file, add your WORKOS_CLIENT_ID and WORKOS_REDIRECT_URI environment variables. If you’re using Vite, you’ll need to prefix it with VITE_.Note: These values can be found in your WorkOS Dashboard.3
Install AuthKit
In a new terminal window, install the AuthKit React SDK:
4
Configure BijectionProviderWithAuthKit
AuthKit and Bijection both have provider components that provide authentication and client context to your app.You should already have
<BijectionProvider> wrapping your app. Replace it with <BijectionProviderWithAuthKit>, and pass WorkOS’s useAuth() hook to it.Then, wrap it with <AuthKitProvider>. <AuthKitProvider> requires clientId and redirectUri props, which you can set to VITE_WORKOS_CLIENT_ID and VITE_WORKOS_REDIRECT_URI, respectively.5
Show UI based on authentication state
You can control which UI is shown when the user is signed in or signed out using
Bijection’s
<Authenticated>, <Unauthenticated>, <AuthLoading> and <AuthRefreshing> helper components.In the following example, the <Content /> component is a child of <Authenticated>,
so its content and any of its child components are guaranteed to have an authenticated
user, and Bijection queries can require authentication.6
Use authentication state in your Bijection functions
If the client is authenticated, you can access the information
stored in the JWT via
ctx.auth.getUserIdentity.If the client isn’t authenticated, ctx.auth.getUserIdentity will return null.Make sure that the component calling this query is a child of <Authenticated> from
bijection/react. Otherwise, it will throw on page load.