Menu

React Mode Integration

React Mode provides RootAuth’s complete UI pages. Only supports React 18+ framework. The instance also includes all methods available in API mode.

 

1. Preparation

Create an application in the RootAuth Console and copy the app_id (format: app_******).

2. Prerequisite

Please add the following configuration line to the .npmrc file in the project root directory:

@rootauth:registry=http://gitlab.standard-software.co/api/v4/projects/12421/packages/npm/

 

3. Install Dependencies

npm install @rootauth/react react react-dom
 

4. Create the RootAuth Page Component

Create a new file RootAuth.tsx (or RootAuth.jsx):

// RootAuth.tsx
import { RootAuthClient, RootAuthMount, type RootAuthClientConfig } from "@rootauth/react";

const options: RootAuthClientConfig = {
  app_id: "******",
  base_path: "/auth",
}
const client = new RootAuthClient(options);

function AuthPage() {
  return <RootAuthMount client={client} />;
}

export default AuthPage;
 

4.1 Configuration Options

React Mode supports exactly the same configuration options as Vue Mode (app_idbase_pathapi_base_urlredirect_urionLoginSuccessonRegisterSuccess, etc.).

interface RootAuthClientConfig {
  app_id: string // Required: obtained from the workspace application configuration
  /** Base path for routes in hosted mode, e.g., '/auth' results in routes like /auth/login, /auth/register, /auth/reset-password, etc.; if omitted, routes start from site root / */
  base_path?: string
  api_base_url?: string // Backend API endpoint path, defaults to https://rootauth-api.rootauth.com
  redirect_uri?: string // Redirect path after successful login, defaults to location.origin
  state?: string // Custom parameter, returned as-is by the API
  locale?: string // Current language, defaults to zh-CN; currently supports zh-CN, en-US
  scope?: string[]  // Scope mapping, defaults to ['openid']; add fields like email, username here to retrieve avatar, username, etc.
  grant_type?: string // Authorization mode, defaults to authorization_code
  enable_google_one_tap?: boolean // Enable Google One Tap login, defaults to false
  /** Hosted mode login success callback; returns false to prevent default redirect */
  onLoginSuccess?: LoginSuccessCallback;
  /** Hosted mode registration success callback; returns false to prevent default redirect */
  onRegisterSuccess?: RegisterSuccessCallback;
}
 

5. Mount in Routes

Add the /auth/* route in your routing configuration file (e.g., App.tsx):

// App.tsx
import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom";
import AuthPage from "./RootAuth";

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/auth/*" element={<AuthPage />} /> // Add the /auth route
      </Routes>
    </BrowserRouter>
  );
}

export default App;
 

6. Other Methods

The client instance in React Mode also supports the following methods:

Method Description
client?.getAppConfig() Get application configuration
client?.logout() Log out and clear the token
client?.getToken() Get the current token
client?.isAuthenticated() Check whether the user is logged in
client?.setLocale('en-US') Switch language (zh-CN / en-US)
Previous
Vue Mode Integration
Next
Error Code Reference
Last modified: 2026-06-10Powered by