# @userfront/react

> Transform your React application with Userfront authentication

Latest version **2.0.3** (published 2025-04-25) · 54 weekly downloads

## Install

```sh
npm install @userfront/react
pnpm add @userfront/react
yarn add @userfront/react
bun add @userfront/react
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2025-04-25 |
| First published | 2020-11-10 |
| Weekly downloads | 54 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 856.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Maintainers | tyrw, steve(at)uf |
| Keywords | userfront, authentication, authorization, javascript, typescript, web, react, sdk |

## Links

- npm: https://www.npmjs.com/package/@userfront/react
- Repository: https://github.com/userfront/userfront
- Homepage: https://github.com/userfront/userfront#readme
- Issues: https://github.com/userfront/userfront/issues
- npm.io page: https://npm.io/package/@userfront/react

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2025-04-25
- 1.0.0-alpha.17 (alpha) — 2023-08-04
- 0.2.20-beta.3 (beta) — 2021-09-25
- 2.0.2-canary.1 — 2025-03-21
- 2.0.1 — 2024-12-06
- 2.0.0 — 2024-06-12
- 1.0.1 — 2024-06-12
- 0.0.1 — 2024-06-07
- 0.3.4 — 2023-08-22
- 1.0.0-alpha.16 — 2023-07-31
- 1.0.0-alpha.15 — 2023-07-13
- 1.0.0-alpha.14 — 2023-07-07
- 1.0.0-alpha.13 — 2023-05-02
- 1.0.0-alpha.12 — 2023-04-28
- 1.0.0-alpha.11 — 2023-04-25
- … 56 more at https://npm.io/package/@userfront/react/versions

## README

<p align="center">
  <br />
  <a href="https://userfront.com">
    <img src="https://raw.githubusercontent.com/userfront/userfront/main/logo.png" width="160">
  </a>
  <br />
</p>

# React SDK

The Userfront React SDK is a fast and easy way to use Userfront in your JavaScript or TypeScript React application.

For Node.js support on the server, see [@userfront/node](https://www.npmjs.com/package/@userfront/node).

For Next.js support on the server and client, see [@userfront/next](https://www.npmjs.com/package/@userfront/next).

## Requirements

- React v18 or later

## Installation

```sh
npm install @userfront/react
# or
yarn add @userfront/react
# or
pnpm add @userfront/react
```

Add the `UserfrontProvider` with your desired `tenantId` to the root layout of your application.

```javascript
import { UserfrontProvider } from "@userfront/react";

function Layout({ children }) {
  return (
    <html lang="en">
      <body>
        <UserfrontProvider tenantId="...">
          {children}
        </UserfrontProvider>
      </body>
    </html>
  );
}
```

### Provider Options

| Option           | Default | Description                                                                                                                                                                   |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tenantId`       | string  | The tenant identifier, this can be found in workspace [Tenants](https://userfront.com/dashboard/tenants) on the Userfront dashboard.                                          |
| `loginUrl`       | string  | Redirect URL for unauthenticated visitors that need to login, the default is `/login`.                                                                                        |
| `loginRedirect`  | string  | Redirect URL after login, `false` to disable. When `undefined`, uses the path configured to the workspace [paths & routing settings](https://userfront.com/dashboard/paths).  |
| `signupRedirect` | string  | Redirect URL after signup, `false` to disable. When `undefined`, uses the path configured to the workspace [paths & routing settings](https://userfront.com/dashboard/paths). |
| `logoutRedirect` | string  | Redirect URL after logout, `false` to disable. When `undefined`, uses the path configured to the workspace [paths & routing settings](https://userfront.com/dashboard/paths). |
| `requireAuth`    | boolean | When `true`, unauthenticated visitors will be redirected to the `loginUrl`.                                                                                                   |

## Usage

### Hook

Use the `useUserfront()` hook to access [Userfront core](https://www.npmjs.com/package/@userfront/core) and the current client auth state.

```javascript
import { useUserfront } from "@userfront/react";

export default function Component() {
  const { user, isLoading } = useUserfront();

  if (isLoading) {
    return <div>Loading...</div>;
  }

  return <div>Hello, {user.email}</div>;
}
```

In addition to core and the `UserfrontProvider` properties, these are also available for use:

| Property          | Type    | Description                                                             |
| ----------------- | ------- | ----------------------------------------------------------------------- |
| `isAuthenticated` | boolean | Whether or not the current visitor is signed into a valid user account. |
| `isLoading`       | boolean | Whether or not Userfront has loaded and initialized.                    |

### Toolkit

[Userfront toolkit](https://www.npmjs.com/package/@userfront/toolkit) components are included in this package. Import and use them without any necessary additional props:

```javascript
import { LoginForm } from "@userfront/react";

export default function Component() {
  return <LoginForm />;
}
```

The available components are `LoginForm`, `SignupForm`, `PasswordResetForm` and `LogoutButton`.

---
_Source: https://npm.io/package/@userfront/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
