/
Contact usSee pricingStart building

    About B2B Saas Authentication

    Introduction
    Stytch B2B Basics
    Integration Approaches
      Full-stack overview
      Frontend (pre-built UI)
      Frontend (headless)
      Backend
    Next.js
      Routing
      Authentication
      Sessions
    Migrations
      Overview
      Reconciling data models
      Migrating user data
      Additional migration considerations
      Zero-downtime deployment
      Defining external IDs for members
      Exporting from Stytch
    Custom Domains
      Overview

    Authentication

    Single Sign On
    • Resources

      • Overview
        External SSO Connections
        Standalone SSO
    • Integration Guides

      • Start here
        Backend integration guide
        Headless integration guide
        Pre-built UI integration guide
    OAuth
    • Resources

      • Overview
        Authentication flows
        Identity providers
        Google One Tap
        Provider setup
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Connected AppsBeta
      Setting up Connected Apps
      Client types
    • Integration Guides

      • Integrate with AI agents
        Integrate with a remote MCP server
    • Resources

      • About Remote MCP Servers
        Consent Management
    Sessions
    • Resources

      • Overview
        JWTs vs Session Tokens
        How to use Stytch JWTs
        Custom Claims
    • Integration Guides

      • Start here
        Backend integration
        Frontend integration
    Email OTP
      Overview
    Magic Links
    • Resources

      • Overview
        Email Security Scanner Protections
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Multi-Factor Authentication
    • Resources

      • Overview
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
        Pre-built UI frontend integration
    Passwords
    • Resources

      • Overview
        Strength policies
    • Integration Guides

      • Pre-built UI frontend integration
    UI components
      Overview
      Implement the Discovery flow
      Implement the Organization flow
    DFP Protected Auth
      Overview
      Setting up DFP Protected Auth
      Handling challenges
    M2M Authentication
      Authenticate an M2M Client
      Rotate client secrets
      Import M2M Clients from Auth0

    Authorization & Provisioning

    RBAC
    • Resources

      • Overview
        Stytch Resources & Roles
        Role assignment
    • Integration Guides

      • Start here
        Backend integration
        Headless frontend integration
    SCIM
    • Resources

      • Overview
        Supported actions
    • Integration Guides

      • Using Okta
        Using Microsoft Entra
    Organizations
      Managing org settings
      JIT Provisioning

    Testing

    E2E testing
    Sandbox values
Get support on SlackVisit our developer forum

Contact us

B2B Saas Authentication

/

Guides

/

Authentication

/

Passwords

/

Integration Guides

/

Pre-built UI frontend integration

B2B Passwords Prebuilt UI Integration

Discovery Flow

In Stytch’s B2B Passwords Discovery flow, end users authenticate before selecting the Organization they want to access by signing in through your application's centralized login page.

This flow is typically used with Cross-Organization passwords, where a single password linked to the user’s email address grants access to any Organization they belong to that has Passwords enabled as an allowed authentication method. This guide walks through how to enable password authentication using Stytch’s frontend SDK with our pre-built UI component. The pre-built UI component handles all password-based flows, including login and signup, password resets, and Organization creation in a seamless, integrated experience.

Steps

1
Complete config steps

If you haven't done so already:

  1. Set up Redirect URLs in the Stytch Dashboard for:
    1. Signup, Login, Invite, Reset password and Discovery types
  2. Enable the Frontend SDKs in your Stytch Dashboard
  3. Enable Cross-Organization passwords by toggling on “Allow Passwords to be used between Organizations” in your Password strength configuration

2
Configure the B2B UI Component

To display Passwords as a login option in the UI, add it to the products array in your UI config and set the authFlowType to “Discovery”.

You can set your desired loginRedirectURL and resetPasswordRedirectURL values within the passwordOptions object. The resetPasswordRedirectURL will be used when the user selects the “Reset Password” button in password reset emails, and the loginRedirectURL will be used when the user selects the “Log in without password” button in password reset emails.

We recommend reviewing the UI Config documentation if you want to explore available styling options.

Most developers choose to place this configuration in a helper file. In this guide we’re doing the same, and you can find this pattern in the companion example app here, but you can alternatively include the config options directly within your Login component.

config.ts

import { AuthFlowType, B2BProducts } from "@stytch/vanilla-js";

export const discoveryConfig = {
  products: [B2BProducts.passwords],
  sessionOptions: { sessionDurationMinutes: 60 },
  passwordOptions: {
    loginRedirectURL: "http://localhost:3000/authenticate",
    resetPasswordRedirectURL: "http://localhost:3000/passwordreset",
    resetPasswordExpirationMinutes: 20
    },
  authFlowType: AuthFlowType.Discovery,
};

export const discoveryStyles = {
  fontFamily: 'Arial',
  container: {
    width: '500px',
  },
}

3
Create the Login UI Component

The example below shows how to create a Login component. It applies the configuration and style defined in your config file. This component automatically handles the UI events and calls the Stytch API with the necessary authentication data. You can then import the Login component into your main application file:

Login.tsx

import { StytchB2B } from "@stytch/react/b2b";
import { discoveryConfig, discoveryStyles } from './config';

export const Login = () => {

  return (
    <div className="centered-login">
      <StytchB2B
      config={discoveryConfig}
      styles={discoveryStyles}
      />
    </div>
  );
};

4
Render the Login component

In this example, there are three routes defined, all of which render the Login component. The /authenticate and /passwordreset routes are the login and password reset redirect URLs defined in the UI configuration.

App.tsx

import { Routes, Route } from "react-router-dom";
import { Login } from "./Login";

export const App = () => {
  return (
    <Routes>
      <Route path="/" element={<Login />} />
      <Route path="/authenticate" element={<Login />}/>
      <Route path="/passwordreset" element={<Login />}/>
    </Routes>
  );
};
  1. A new user can sign up by clicking the ‘Sign up or reset password’ link

    Pre-built UI integration of discovery passwords - sign up
  2. A new user is prompted to enter their email. This triggers a verification email containing a magic link. The link includes a unique token that validates the user and allows them to create a password.

    Pre-built UI integration of discovery passwords - enter email
  3. The verification email can be customized in the Email Templates section of your Dashboard as the Passwords > Email verification template type.

    Pre-built UI integration of discovery passwords - email magic link
  4. Upon clicking the ‘Reset Password’ button, a user is redirected to the Password Reset redirect url, where they can enter a new password

    Pre-built UI integration of discovery passwords - set password
  5. The user is prompted to select the Organization they want to access. If the user does not have access to any Organizations, they can create a new one by clicking the ‘Create an organization’ button.

    Pre-built UI integration of discovery passwords - select organization
  6. This setting can be configured in the Frontend SDK settings in the Stytch Dashboard, as well as in your UI configurations. Note that the Dashboard settings will take precedence over the UI configurations. The email address is redacted in the image below.

    Pre-built UI integration of discovery passwords - create organization
  7. If a new user does not have access to any Organizations and the ‘Create Organization’ method is not enabled, the user is advised to reach out to an administrator.

    Pre-built UI integration of discovery passwords - try different email
  1. A returning user can log in with their email and password

    Pre-built UI integration of discovery passwords - login
  2. The user is prompted to select the Organization they want to access.

    Pre-built UI integration of discovery passwords - select organization
  3. The user is now successfully logged in.

    Pre-built UI integration of discovery passwords - successful login
  1. The user can choose to reset their password by clicking the “Sign up or reset password” link.

    Pre-built UI integration of discovery passwords - password reset
  2. The user is prompted to enter their email. This triggers a password reset email containing a magic link. The link includes a unique token that validates the user and allows them to reset their password.

    Pre-built UI integration of discovery passwords - enter email
  3. The Password Reset email can be customized in the Email Templates section of your Dashboard as the Passwords > Password reset template type.

    Pre-built UI integration of discovery passwords - email magic link
  4. Upon clicking the ‘Reset Password’ button, the user is redirected to the Password Reset redirect url, where they can enter a new password.

    Pre-built UI integration of discovery passwords - set password
  5. The user is prompted to select the Organization they want to access.

    Pre-built UI integration of discovery passwords - select org
  6. The user is now successfully logged in

    Pre-built UI integration of discovery passwords - successful login

Discovery Flow

Steps

1.

Complete config steps

2.

Configure the B2B UI Component

3.

Create the Login UI Component

4.

Render the Login component