Next.js
Integrate Rownd instant accounts and authentication into your Next.js project, including support for server-side rendering
Installation
Run npm install @rownd/next
or yarn add @rownd/next
.
Core Components
RowndProvider
The root component that initializes Rownd authentication and state management. Add this to your root layout:
In the root layout.tsx
of your app:
Prop | Description | Required | Default |
---|---|---|---|
appKey | Your unique Rownd application identifier | Yes | - |
apiUrl | Enterprise API endpoint for Rownd services | No | https://api.rownd.io |
hubUrlOverride | Enterprise URL for the Rownd authentication hub interface | No | https://hub.rownd.io |
π‘ Note
Enterprise endpoints are not needed in most use-cases and these props will default to Rowndβs commercial cloud
Middleware Setup
In your main middleware.ts
file, add the Rownd middleware higher-order function. As well as the Rownd token callback path:
Authentication Components
Protected Routes / Pages
To protect a page from being accessed by unauthenticated users, you can use
the withRowndRequireSignIn
higher-order component.
Client-Side Authentication
Use the useRownd
hook to access authentication state and methods:
Server Utilities
getRowndUser
Server-side function to get the current authenticated user:
State Management
The SDK uses a custom store implementation for managing authentication state. The store includes:
Available Methods
The useRownd
hook provides the following methods:
Method | Description | Return Type |
---|---|---|
requestSignIn() | Triggers the sign-in modal | void |
signOut() | Signs out the current user | void |
setUser() | Updates user data | Promise<UserContext> |
getAccessToken() | Gets the current access token | Promise<string> |
manageAccount() | Opens the account management interface | void |
getFirebaseIdToken() | Gets the Firebase ID token | Promise<string> |
setUserValue() | Updates specific user field | Promise<UserContext> |
API reference
Please see the React SDK for details on Rownd Client React APIβs.