/
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
      About Remote MCP Servers
    • Resources

      • Integrate with AI agents
        Integrate with a remote MCP server
    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
      Overview
      Strength policies
    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

/

Authorization & Provisioning

/

RBAC

/

Integration Guides

/

Headless frontend integration

Headless Integration of RBAC

While it is important to always have server-side authentication and authorization checks, Stytch's frontend SDKs offer:

  • Built-in RBAC protections for Stytch methods
  • Client side RBAC policy evaluations to minimize unnecessary, unauthorized requests to the server
  • Methods for viewing all permissions for the currently logged in user, to make it easy to conditionally render UI elements

Stytch Resource Authorization Checks

Stytch's frontend SDKs offer built-in RBAC protections for Stytch member and organization management SDK methods, allowing you to make these requests directly from your public client instead of proxying through your server.

To enable this functionality, turn on "Member actions & permissions" in the FE SDKs section of the Stytch Dashboard.

Enable RBAC member actions and permissions for FE SDKs

You can then call methods like organization.update() or magicLinks.email.invite() directly from the client, and the frontend SDK will automatically include the logged in member's session in the request.

Stytch's backend will only authorize the request if the session is valid and the session Member has at least one Role that grants them permission to take that action.

Client Side Authorization Checks

While there should always be server-side authorization checks occuring (whether on Stytch's servers, when calling Stytch methods, or on your own servers for application specific actions) Stytch's SDKs provide a way to do a pre-emptive client-side authorization check to avoid any unnecessary API requests or ensure the user isn't about to enter a flow they cannot complete.

For example, in vanilla Javascript you would perform a check like this before allowing a user to edit a document:

<button disabled={!isAuthorized} onClick={editDocument}>Edit</button>

<script>
    import { StytchB2BHeadlessClient } from '@stytch/vanilla-js/b2b/headless';
    const stytch = new StytchB2BHeadlessClient('STYTCH_PUBLIC_TOKEN');
    const isAuthorized = stytch.rbac.isAuthorizedSync('documents', 'update');
    const editDocument = () => {
    //...
    };
</script>

See the SDK reference docs for more details on differences between frameworks.

Conditional Rendering of Authorized Actions

In order to conditionally render parts of your UI based on the logged in Member's permissions (such as showing an edit button as enabled or disabled) you can use the allPermissions() method, or in React the HOC (higher-order component) of withStytchPermissions.

For example, using our React SDK you would do the following:

import { withStytchPermissions } from '@stytch/react/b2b';

const MyComponent = (props) => {
  const canEditDocuments = props.stytchPermissions['document']['edit'];
  const canEditOrgName = props.stytchPermissions['stytch.organization']['update.info.name']

  return (
    <>
      <button disabled={!canEditDocuments} onClick={editDocument}>Edit Document</button>;
      <button disabled={!canEditOrgName} onClick={updateOrgName}>Update Organization Name</button>;
    </>
  )
}

export default withStytchPermissions(MyComponent);

Stytch Resource Authorization Checks

Client Side Authorization Checks

Conditional Rendering of Authorized Actions