The React Native SDK provides the option for you to use pre-built login flows, supporting dark and light themes, with easy configuration, detailed below.
UI Configuration
Handling Deeplinks
For Email Magic Links, OAuth, SSO, and Password Reset flows, this component handles the deeplinking automatically. You'll need to add a custom URL scheme and redirect URL as explained below.
First, you need to configure your app to listen for a deeplink with the scheme: stytch-ui-[YOUR_PUBLIC_TOKEN]. How you do that will depend on your supported platforms and whether you are using bare React Native or Expo.
NOTE If you are using Expo Router, which is the default for new apps created with create-expo-app, you must add a +native-intent.tsx file which ignores the incoming Stytch UI deep links. An example of this can be found here.
Lastly, you'll need to add a special redirect URL in your Stytch Dashboard Redirect URLs. It should have a URL of stytch-ui-[YOUR_PUBLIC_TOKEN]://deeplink and be applied to all redirect types.
Once both the scheme (in your app) and the redirect URL (in your Dashboard) are configured, our pre-built UI should handle the rest.
Fields
The Stytch B2B client object.
The config object for the UI components.
The products array allows you to specify the authentication methods that you would like to expose to your users.
The order of the products that you include here will also be the order in which they appear in the login form, with the first product specified appearing at the top of the login form.
Currently the JavaScript B2B SDK supports our emailMagicLinks, oauth, sso, and passwords products.
emailMagicLinks and oauth are supported in both authentication flow types, whereas sso is only supported in the Organization authentication flow type. passwords is always supported in the Organization authentication flow type, but is also supported in the Discovery flow if cross-org passwords are enabled for the project.
If the only product specified is oauth, and the only OAuth provider specified is google with one_tap set to true, the login form will not be displayed. Instead, we will only show the Google one tap prompt in the upper right of the user's browser.
The authFlowType lets you specify the authentication flow type that you wish to enable in the SDK. The options are Discovery to let members log into any organization they are a part of; Organization to let members log into a specific organization; and PasswordReset to handle password reset flows (after the user clicks the password reset redirect URL). To enable the Organization flow type, you also must add a slug pattern to the authorized domain through the Frontend SDK page in the Dashboard.
The options for session management. We create a session for members when they log in. You can access a member or session using the Member or Session SDK methods.
Set the session lifetime to be this many minutes from now; minimum of 5 and a maximum of 525600 minutes (365 days). Note that a successful authentication will continue to extend the session this many minutes.
The options for email magic links. This is required if emailMagicLinks is present in the products array.
Custom template ID for login emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Login.
Custom template ID for sign-up emails. By default, it will use your default email template. The template must be a template using our built-in customizations or a custom HTML email for Magic links - Sign-up.
The options for Passwords. This is required if passwords is present in the products array.
The number of minutes that the password reset token sent in password reset emails will be valid for. Defaults to 30 minutes.
Custom template ID for password reset emails, configured via the Branding page in the Stytch Dashboard. If this value is not specified, your default password reset template will be used.
The options for OAuth. This is required if oauth is present in the products array.
Specifies which OAuth providers to display.
The provider type. Currently we support google, microsoft, hubspot, slack, and github.
An optional array of scopes that Stytch will request for your application in addition to the base set of scopes required for login.
An object with any additional parameters that you'd like to pass along to the OAuth provider (for example, login_hint, for providers that support it).
A configuration option that allows you to skip the discovery flow and log a member in directly only if they are a member of a single organization.
Whether or not direct login for single membership is enabled. If the user has an invite or can JIT provision into an Organization the Discovery Organization select pane will still be shown unless the other two properties are also enabled.
If enabled, logs a user directly into their existing Organization even if they have one or more pending invites to a different Organization. This bypasses the Discovery Organization select pane.
If enabled, logs a user directly into their existing Organization even if they have Organizations they could join via JIT provisioning. This bypasses the Discovery Organization select pane.
Whether or not an organization should be created directly when a user has no memberships, invitations, or organizations they could join via JIT provisioning. This has no effect if the ability to create organizations from the frontend SDK is disabled in the Stytch Dashboard. Defaults to false.
Whether to prevent users who are not members of any organization from creating a new organization during the discovery flow. This has no effect if the ability to create organizations from the frontend SDK is disabled in the Stytch Dashboard. Defaults to false.
The order to present MFA products to a member when multiple choices are available, such as during enrollment.
Currently the JavaScript B2B SDK supports our smsOtp and totp MFA products.
MFA products to include in the UI. If specified, the list of available products will be limited to those included. Defaults to all available products.
Note that if an organization restricts the available MFA methods, the organization's settings will take precedence. In addition, if a member is enrolled in MFA compatible with their organization's policies, their enrolled methods will always be made available.
Currently the JavaScript B2B SDK supports our smsOtp and totp MFA products.
The slug of the organization to present login options for. This is only used when the config.authFlowType is AuthFlowType.Organization.
An object that configures the dark and light themes used by the login UI
Styles that will be applied on devices in dark mode
Styles that will be applied on devices in light mode
Optional callbacks that are triggered by various events in the SDK. See more details about the callbacks here.
A callback function that responds to events sent from the SDK.
A callback function that responds to errors in the SDK. It is useful for debugging during development and error handling in production.
import React from 'react';
import {
StytchB2BUI,
StytchRNB2BUIConfig,
AuthFlowType,
B2BProducts,
B2BOAuthProviders,
Callbacks,
StytchEventType,
} from '@stytch/react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';
const Login = ({ navigation }) => {
const stytch = useStytchB2BClient();
const callbacks: Callbacks = {
onEvent(event) {
if (event.type == StytchEventType.AuthenticateFlowComplete) {
navigation.navigate('Profile');
}
},
};
const config: StytchRNB2BUIConfig = {
productConfig: {
products: [B2BProducts.emailMagicLinks, B2BProducts.oauth, B2BProducts.passwords, B2BProducts.sso],
authFlowType: AuthFlowType.Organization,
sessionOptions: { sessionDurationMinutes: 60 },
oauthOptions: {
providers: [B2BOAuthProviders.Google],
},
},
organizationSlug: 'your-organization-slug',
};
return <StytchB2BUI client={stytch} config={config} callbacks={callbacks}></StytchB2BUI>;
};
export default Login;