Skip to main content

Quick Navigation

SectionDescription
InstallationHow to install the React SDK
Basic SetupSetting up the RowndProvider
Authentication StatesFour possible auth states and handling
User ManagementWorking with user data and profiles
Sign In OptionsCustomizing the sign-in experience
HTML HooksUsing declarative data attributes
Type DefinitionsTypeScript interfaces and types
Best PracticesRecommended patterns and approaches
Advanced FeaturesAdvanced SDK capabilities
API IntegrationMaking authenticated API calls
Account ManagementManaging user accounts

Installation

Simply run npm install @rownd/react or yarn add @rownd/react.

Usage

The library provides a React provider and hook for the Rownd browser API. In your app’s main entrypoint, add the Rownd provider, likely before other providers:
The Rownd React SDK automatically injects the Rownd Hub snippet into your React application, so you should not manually include the Hub snippet in your HTML page. Doing so will produce unexpected results.
Rownd has a number of built in features including getAccessToken() which will fetch your token. Rownd’s SDK automatically checks the token and do token refreshes. Rownd takes care of the UI for your app as well.

Provider Configuration

The RowndProvider component accepts the following configuration options:
PropertyTypeRequiredDescription
appKeystringYesThe application key generated in the Rownd dashboard. This uniquely identifies your application.
postLoginRedirectstringNoURL where users will be redirected after successful sign-in. If not provided, users stay on the current page.
postRegistrationRedirectstringNoURL where new users will be redirected after registration. Useful for onboarding flows.
rootOriginstringNoRoot domain for multi-domain setups (e.g., “https://yourdomain.com”). Used when your app spans multiple subdomains.

The useRownd Hook

The useRownd hook is your primary interface for accessing authentication state and user data. It provides a comprehensive set of properties and methods:

State Properties

PropertyTypeDescriptionUsage Example
is_initializingbooleanIndicates if Rownd is still loading. Always check this before making auth-dependent decisions.if (is_initializing) return <Loading />
is_authenticatedbooleanWhether the user is currently signed in.if (is_authenticated) showDashboard()
access_tokenstringThe current JWT access token. Updates automatically when refreshed.headers: { Authorization: Bearer ${access_token} }
user.dataobjectThe user’s profile data. Contains all user fields.const { first_name, email } = user.data
user.is_loadingbooleanWhether user data is being loaded/updatedif (user.is_loading) showSpinner()

Authentication Methods

MethodDescriptionParametersReturn Type
requestSignIn()Triggers the sign-in flow{ auto_sign_in?: boolean, identifier?: string, method?: string }void
signOut()Signs out the current userNonevoid
getAccessToken()Gets the current access token{ waitForToken?: boolean }Promise<string>

User Data Methods

MethodDescriptionParametersReturn Type
setUser()Updates multiple user fieldsRecord<string, any>Promise<void>
setUserValue()Updates a single user field(field: string, value: any)Promise<void>
manageAccount()Opens account management UINonevoid

User Object Structure

The user object provides comprehensive information about the current user:
PropertyTypeDescription
user.data()objectUser’s profile data including custom fields
user.data.{data-type}VariesUser’s profile data including custom fields; for example; first_name
user.groupsstring[]Groups the user belongs to

Example User Data Structure

Note: The actual fields available in user.get() will depend on your application’s configuration in the Rownd dashboard. The example above shows common fields, but you can add custom fields as needed for your application.

Authentication State

The auth object provides detailed authentication information:
PropertyTypeDescription
auth.access_tokenstringCurrent JWT access token
auth.app_idstringID of the current application
auth.is_authenticatedbooleanWhether user is authenticated
auth.is_verified_userbooleanWhether user has verified credentials
auth.auth_levelstringCurrent authentication level

Events API

The SDK provides an event system to react to various state changes:

App Configuration

Access application configuration:

Firebase Integration

For applications using Firebase:

Passkey Authentication

Complete passkey implementation:

Complete User Profile Management

Example showing comprehensive user data management:

Type Definitions

For TypeScript users, here are the comprehensive interfaces:

TypeScript Examples

Type-Safe Authentication Component

Type-Safe User Profile Component

Type-Safe API Integration

Examples

Authentication States

The Rownd SDK has four possible states based on is_initializing and is_authenticated:
This pattern can be applied to any component that needs to handle authentication states. Here’s a more specific example:
You can also create reusable components for each state:
This approach can also be used with API calls:

Best Practices

  1. Always Check Initialization
  2. Handle Loading States
  1. Use Proper Token Handling
  2. Implement Error Boundaries
  3. Efficient Token Handling
  4. Token Decoding Example
  5. API Route Best Practices
This approach:
  • Reduces payload size
  • Prevents token/ID mismatch
  • Improves security by relying on verified token data
  • Simplifies API implementations
  • Reduces potential for user spoofing

Advanced Features

1. Custom Sign-in Flows

2. File Uploads

For more details on specific APIs and features, refer to the JavaScript API Reference.

Sign In Request Options

The requestSignIn method accepts several configuration options to customize the sign-in experience:

Examples

HTML Hooks Integration

While the React SDK provides programmatic control, you can also use HTML data attributes for declarative authentication controls. These work alongside React components:

Declarative Authentication Components

The React SDK provides three declarative components for handling authentication states: <RequireSignIn />, <SignedIn />, and <SignedOut />. These components make it easy to conditionally render content based on authentication state without manually checking is_authenticated.

RequireSignIn

The <RequireSignIn /> component forces users to sign in before accessing protected content. If a user is not authenticated, it will automatically trigger the sign-in flow.
You can customize the sign-in behavior with props:

SignedIn and SignedOut

These components conditionally render their children based on authentication state:
Both components accept a loadingComponent prop to customize the loading state:

Combining Components

You can combine these components to create complex authentication flows:

Best Practices

  1. Use RequireSignIn for Protected Routes
  2. Combine with React Router
  3. Handle Loading States
  4. Nested Authentication
These declarative components provide a clean, intuitive way to handle authentication states in your React application, reducing boilerplate code and making authentication flows more maintainable.

Account Management

Using manageAccount()

The manageAccount() function provides a pre-built, customizable account management interface that saves significant development time. This Rownd-generated system handles common user management tasks out of the box.

Features Included

The account management interface provides:
FeatureDescription
Profile EditingUsers can update their basic information (name, email, etc.)
Email VerificationHandles email verification status and re-verification
Password ManagementChange password and set up passwordless options
Connected AccountsManage social logins and connected services
Security Settings2FA setup, passkey management, session control
Data AccessView and download personal data
Account DeletionSelf-service account removal option

Customization Options

You can customize the account management interface through the Rownd Dashboard:
  1. Branding
    • Custom colors and themes
    • Logo placement
    • Typography settings
  2. Field Configuration
    • Show/hide specific fields
    • Mark fields as required
    • Add custom fields
    • Set field validation rules
  3. Feature Toggles
    • Enable/disable specific features
    • Configure verification requirements
    • Set up data retention policies

Integration Example

Best Practices

  1. Accessibility
  2. Context-Aware Placement
return ( ); }
By using manageAccount(), you get a complete user account management system without building and maintaining custom interfaces. This significantly reduces development time while providing a consistent, secure, and feature-rich experience for your users.

Accessing User Data

There are two ways to access user data in your application:
  1. Using the useRownd Hook (Recommended)
  1. Using HTML Data Attributes

Important Notes:

  • Always access user data through user.data when using the hook
  • Fields are accessed directly in HTML templates (e.g., {{ first_name }} not {{ user.data.first_name }})
  • Both methods require being within a <RowndProvider> context
  • Both methods automatically update when user data changes

Combined Example: