2.0.1 • Published 7 months ago

@userfront/react v2.0.1

Weekly downloads
3
License
-
Repository
github
Last release
7 months ago

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.

For Next.js support on the server and client, see @userfront/next.

Requirements

  • React v18 or later

Installation

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.

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

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

Provider Options

OptionDefaultDescription
tenantIdstringThe tenant identifier, this can be found in workspace Tenants on the Userfront dashboard.
loginUrlstringRedirect URL for unauthenticated visitors that need to login, the default is /login.
loginRedirectstringRedirect URL after login, false to disable. When undefined, uses the path configured to the workspace paths & routing settings.
signupRedirectstringRedirect URL after signup, false to disable. When undefined, uses the path configured to the workspace paths & routing settings.
logoutRedirectstringRedirect URL after logout, false to disable. When undefined, uses the path configured to the workspace paths & routing settings.
requireAuthbooleanWhen true, unauthenticated visitors will be redirected to the loginUrl.

Usage

Hook

Use the useUserfront() hook to access Userfront core and the current client auth state.

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:

PropertyTypeDescription
isAuthenticatedbooleanWhether or not the current visitor is signed into a valid user account.
isLoadingbooleanWhether or not Userfront has loaded and initialized.

Toolkit

Userfront toolkit components are included in this package. Import and use them without any necessary additional props:

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

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

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

2.0.1

7 months ago

1.0.1

1 year ago

2.0.0

1 year ago

0.0.1

1 year ago

1.0.0-alpha.16

2 years ago

1.0.0-alpha.15

2 years ago

1.0.0-alpha.17

2 years ago

1.0.0-alpha.14

2 years ago

0.3.4

2 years ago

1.0.0-alpha.9

2 years ago

1.0.0-alpha.8

2 years ago

1.0.0-alpha.7

2 years ago

1.0.0-alpha.6

2 years ago

1.0.0-alpha.10

2 years ago

1.0.0-alpha.5

2 years ago

1.0.0-alpha.4

2 years ago

1.0.0-alpha.3

2 years ago

1.0.0-alpha.2

2 years ago

1.0.0-alpha.1

2 years ago

1.0.0-alpha.12

2 years ago

1.0.0-alpha.11

2 years ago

1.0.0-alpha.13

2 years ago

0.3.2

2 years ago

0.3.3

2 years ago

0.2.23

3 years ago

0.3.1

3 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.20-beta.0

4 years ago

0.2.20-beta.3

4 years ago

0.2.20-beta.1

4 years ago

0.2.20-beta.2

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.1.27

4 years ago

0.2.1

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.4

4 years ago

0.1.25

4 years ago

0.1.26

4 years ago

0.1.24

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.21

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.12

5 years ago

0.1.13

5 years ago

0.1.10

5 years ago

0.1.11

5 years ago

0.1.8

5 years ago

0.1.9

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.4

5 years ago

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago