Skip to main content

Quick Navigation

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:

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

Authentication Methods

User Data Methods

User Object Structure

The user object provides comprehensive information about the current user:

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:

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:

Available HTML Hooks

Combining React and HTML Approaches

You can mix programmatic and declarative approaches:

Best Practices for Authentication Flow

  1. Global vs. Local Redirects
  2. Progressive Enhancement
  3. Handling Different Auth States

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:

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: