Quick Navigation
Installation
Simply runnpm 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
TheuseRownd 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
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 onis_initializing and is_authenticated:
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
- 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
Sign In Request Options
TherequestSignIn 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.
SignedIn and SignedOut
These components conditionally render their children based on authentication state: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
Account Management
Using manageAccount()
ThemanageAccount() 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:-
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
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.datawhen 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