Quick Navigation
| Section | Description |
|---|
| Installation | How to install the React SDK |
| Basic Setup | Setting up the RowndProvider |
| Authentication States | Four possible auth states and handling |
| User Management | Working with user data and profiles |
| Sign In Options | Customizing the sign-in experience |
| HTML Hooks | Using declarative data attributes |
| Type Definitions | TypeScript interfaces and types |
| Best Practices | Recommended patterns and approaches |
| Advanced Features | Advanced SDK capabilities |
| API Integration | Making authenticated API calls |
| Account Management | Managing 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:
| Property | Type | Required | Description |
|---|
appKey | string | Yes | The application key generated in the Rownd dashboard. This uniquely identifies your application. |
postLoginRedirect | string | No | URL where users will be redirected after successful sign-in. If not provided, users stay on the current page. |
postRegistrationRedirect | string | No | URL where new users will be redirected after registration. Useful for onboarding flows. |
rootOrigin | string | No | Root 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
| Property | Type | Description | Usage Example |
|---|
is_initializing | boolean | Indicates if Rownd is still loading. Always check this before making auth-dependent decisions. | if (is_initializing) return <Loading /> |
is_authenticated | boolean | Whether the user is currently signed in. | if (is_authenticated) showDashboard() |
access_token | string | The current JWT access token. Updates automatically when refreshed. | headers: { Authorization: Bearer ${access_token} } |
user.data | object | The user’s profile data. Contains all user fields. | const { first_name, email } = user.data |
user.is_loading | boolean | Whether user data is being loaded/updated | if (user.is_loading) showSpinner() |
Authentication Methods
| Method | Description | Parameters | Return Type |
|---|
requestSignIn() | Triggers the sign-in flow | { auto_sign_in?: boolean, identifier?: string, method?: string } | void |
signOut() | Signs out the current user | None | void |
getAccessToken() | Gets the current access token | { waitForToken?: boolean } | Promise<string> |
User Data Methods
| Method | Description | Parameters | Return Type |
|---|
setUser() | Updates multiple user fields | Record<string, any> | Promise<void> |
setUserValue() | Updates a single user field | (field: string, value: any) | Promise<void> |
manageAccount() | Opens account management UI | None | void |
User Object Structure
The user object provides comprehensive information about the current user:
| Property | Type | Description |
|---|
user.data() | object | User’s profile data including custom fields |
user.data.{data-type} | Varies | User’s profile data including custom fields; for example; first_name |
user.groups | string[] | 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:
| Property | Type | Description |
|---|
auth.access_token | string | Current JWT access token |
auth.app_id | string | ID of the current application |
auth.is_authenticated | boolean | Whether user is authenticated |
auth.is_verified_user | boolean | Whether user has verified credentials |
auth.auth_level | string | Current 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
-
Always Check Initialization
-
Handle Loading States
-
Use Proper Token Handling
-
Implement Error Boundaries
-
Efficient Token Handling
-
Token Decoding Example
-
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
-
Use RequireSignIn for Protected Routes
-
Combine with React Router
-
Handle Loading States
-
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:
| Feature | Description |
|---|
| Profile Editing | Users can update their basic information (name, email, etc.) |
| Email Verification | Handles email verification status and re-verification |
| Password Management | Change password and set up passwordless options |
| Connected Accounts | Manage social logins and connected services |
| Security Settings | 2FA setup, passkey management, session control |
| Data Access | View and download personal data |
| Account Deletion | Self-service account removal option |
Customization Options
You can customize the account management interface through the Rownd Dashboard:
-
Branding
- Custom colors and themes
- Logo placement
- Typography settings
-
Field Configuration
- Show/hide specific fields
- Mark fields as required
- Add custom fields
- Set field validation rules
-
Feature Toggles
- Enable/disable specific features
- Configure verification requirements
- Set up data retention policies
Integration Example
Best Practices
-
Accessibility
-
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:
- Using the useRownd Hook (Recommended)
- 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: