React Quickstart

This quickstart resource covers the essential considerations and steps required to start integrating Stytch’s B2B SaaS Authentication product within a React application.


Stytch offers developers a React SDK that can be used within a React application:





Source Code

React SDK


Can be used in client-side code and components. Our React SDK offers pre-built UI components with customizable login and signup forms, alongside a collection of headless methods for integrating with your own custom UI.

SDK Reference


Even if you're using our client-side Next.js SDK, you will also want to leverage one of our server-side SDKs in order to handle server-side session authentication and authorization checks.

You can read more about the differences and tradeoffs between each integration method (backend, frontend headless, and frontend with pre-built UI) by visiting our integration guides.

Getting started

To get started, we'll quickly set up a Discovery flow login form with our prebuilt UI components.

Pre-built UI component with Stytch's React SDK

1Install Stytch SDKs and configure your API keys

If you haven't already, create a Stytch B2B Project in your Stytch Dashboard.

Add our frontend React SDK package to your React application:

npm install @stytch/react @stytch/vanilla-js --save

Add your Stytch Project's public_token to your application as an environment variable in a .env file:

# .env
# The below values may be found in your Stytch Dashboard:

2Configure Stytch SDK settings

To allow the Stytch SDK to run on your frontend, you'll also need to:

  1. Enable frontend SDKs in Test in your Stytch Dashboard here.
  2. Add the domain your application will run on (e.g. http://localhost:3000) to the list of Domains under Authorized applications.
  3. Enable the Create organizations toggle under Enabled methods. This isn't required, but this setting will allow users to create new Organizations directly from our SDK.

3Create the UI client and wrap your application in <StytchB2BProvider>

First, initialize the Stytch UI client by invoking the createStytchB2BUIClient constructor function, passing in your Project's public token.

Next, pass the Stytch UI client to the StytchB2BProvider component at the root of your application, making it accessible to all child components.

import { StytchB2BProvider } from '@stytch/react/b2b';
import { StytchB2BUIClient } from '@stytch/vanilla-js/b2b';

const stytch = new StytchB2BUIClient(
  import.meta.env.STYTCH_PUBLIC_TOKEN // or process.env.STYTCH_PUBLIC_TOKEN for non-Vite based projects

const root = ReactDOM.createRoot(document.getElementById("root"));

    <StytchB2BProvider stytch={stytch}>
      <App />

4Add the <StytchB2B> UI component

Create a StytchB2B component. You can configure which authentication flow and methods you'd like to offer by modifying the authFlowType and products fields respectively in your config object.

Here's an example of our pre-built UI component utilizing our Discovery flow and Email Magic Links:

import { StytchB2B } from '@stytch/react/b2b';
import { AuthFlowType, B2BProducts } from '@stytch/vanilla-js/b2b';

const LoginOrSignup = () => {
   const config = {
      products: [B2BProducts.emailMagicLinks],
      sessionOptions: { sessionDurationMinutes: 60 },
      authFlowType: AuthFlowType.Discovery,

   return <StytchB2B config={config} />;

For Email Magic Links, you must specify a redirect URL in your Project's Dashboard to authenticate the token. By default, the redirect URL is set to http://localhost:3000/authenticate.

If the <StytchB2B> component is rendered on the redirect URL used for this flow, the Email Magic Link token will automatically be authenticated. You can specify additional Redirect URLs in your Project's Dashboard, and override the default by passing in an explicit emailMagicLinksOptions.discoveryRedirectURL to your UI config.

You can read more about redirect URLs in this guide.

5What's next

Check out our product-specific guides for how to handle full authentication flows for each product you'd like to support, like Email Magic Links and OAuth.