# React authentication libraries

React authentication libraries sign users in and give components access to the current session. Most connect the app to a hosted identity provider or a server-side auth framework through hooks, providers, and prebuilt sign-in components. These libraries let apps protect pages and API calls for signed-in users.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Better Auth](#better-auth) | 72.7M | 30.8K | Nov 2026 | MIT |
| [NextAuth.js](#nextauth-js) | 36.3M | 28.4K | Jul 2026 | ISC |
| [Clerk](#clerk-react) | 16.8M | 1.8K | Nov 2026 | MIT |
| [Auth0 React](#auth-react) | 8.9M | 992 | Oct 2026 | MIT |
| [MSAL React](#msal-react) | 7.1M | 4.2K | Nov 2026 | MIT |
| [@react-oauth/google](#react-oauth-google) | 6.5M | 1.3K | Apr 2026 | MIT |
| [react-oidc-context](#react-oidc-context) | 4.2M | 1.0K | Mar 2026 | MIT |
| [@workos-inc/authkit-react](#workos-inc-authkit-react) | 2.3M | 48 | Sep 2026 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Better Auth](#better-auth) has the most monthly downloads in this comparison, at 72.7M.

## Capabilities

| Library | Custom OIDC issuer | Bundled sign-in form |
| --- | --- | --- |
| [Better Auth](#better-auth) | Via plugin | No |
| [NextAuth.js](#nextauth-js) | Yes | Yes |
| [Clerk](#clerk-react) | No | Yes |
| [Auth0 React](#auth-react) | No | No |
| [MSAL React](#msal-react) | Yes | No |
| [@react-oauth/google](#react-oauth-google) | No | No |
| [react-oidc-context](#react-oidc-context) | Yes | No |
| [@workos-inc/authkit-react](#workos-inc-authkit-react) | No | No |

## Libraries

### Better Auth

[GitHub](https://github.com/better-auth/better-auth) · [npm](https://www.npmjs.com/package/better-auth) · [Docs](https://www.better-auth.com/docs)

Provides an authentication framework for TypeScript.

- Downloads / mo: 72.7M
- Stars: 30.8K
- Last release: 1.7.26
- License: MIT
- Capabilities: [From the Better Auth docs](https://www.better-auth.com/docs)

```sh
npm i better-auth
```

**better-auth-ui/better-auth-ui** (1.7K stars)

[better-auth-ui/better-auth-ui](https://github.com/better-auth-ui/better-auth-ui) 

```tsx
export function signInEmailOptions<TAuthClient extends AuthClient>(
  authClient: TAuthClient
) {
  const mutationKey = authMutationKeys.signIn.email

  const mutationFn = (params: SignInEmailParams<TAuthClient>) =>
    authClient.signIn.email({
      ...params,
      fetchOptions: { ...params.fetchOptions, throw: true }
    })

  return {
    mutationKey,
    mutationFn,
    meta: {
      awaits: [authQueryKeys.session]
    }
  } as MutationOptions<
    Awaited<ReturnType<typeof mutationFn>>,
    BetterFetchError,
    Parameters<typeof mutationFn>[0]
  >
}

```

[packages/core/src/mutations/sign-in-email-mutation.ts](https://github.com/better-auth-ui/better-auth-ui/blob/5767ba5568cf4798b2a222652bfefbf8d57f0152/packages/core/src/mutations/sign-in-email-mutation.ts#L21-L43) · [More projects using Better Auth →](https://dashboard.exa.ai/playground/search?q=better-auth%20GitHub%20projects)

**Quickstart**

```tsx
import { createAuthClient } from "better-auth/react";
const authClient = createAuthClient({ baseURL: "http://localhost:3000" });
const { data: session, error } = await authClient.getSession();

```

From [client.mdx](https://www.better-auth.com/docs/concepts/client)

### NextAuth.js

[GitHub](https://github.com/nextauthjs/next-auth) · [npm](https://www.npmjs.com/package/next-auth) · [Docs](https://next-auth.js.org/)

Connects React session controls to authentication configured in a Next.js application.

- Downloads / mo: 36.3M
- Stars: 28.4K
- Last release: 4.24.15
- License: ISC
- Capabilities: [From the NextAuth.js docs](https://next-auth.js.org/)

**Strengths**

- **Configures sign-in providers in Next.js.** Configure the providers in the application's own Next.js authentication route.
- **Controls the client session payload.** Choose which extra session fields reach the browser.

**Watch out for**

- **Credentials users are not persisted.** Store account records through the application's existing authentication system.
- **Provider tokens need explicit exposure.** Add provider access tokens through JWT and session callbacks.

```sh
npm install next-auth
```

**shadcn-ui/taxonomy** (19.3K stars)

[shadcn-ui/taxonomy](https://github.com/shadcn-ui/taxonomy) 

```jsx
async function onSubmit(data: FormData) {
  setIsLoading(true)

  const signInResult = await signIn("email", {
    email: data.email.toLowerCase(),
    redirect: false,
    callbackUrl: searchParams?.get("from") || "/dashboard",
  })

  setIsLoading(false)

  if (!signInResult?.ok) {
    return toast({
      title: "Something went wrong.",
      description: "Your sign in request failed. Please try again.",
      variant: "destructive",
    })
  }

  return toast({
    title: "Check your email",
    description: "We sent you a login link. Be sure to check your spam too.",
  })
}

```

[components/user-auth-form.tsx](https://github.com/shadcn-ui/taxonomy/blob/298a8857c7128a0d121e7f699dfd729f23b3966d/components/user-auth-form.tsx#L34-L57) · [More projects using NextAuth.js →](https://dashboard.exa.ai/playground/search?q=React%20TypeScript%20projects%20using%20next-auth%20for%20sign-in%20forms%2C%20protected%20API%20tokens%2C%20consent%20recovery%20and%20conditional%20authentication%20controls&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```jsx
import { SessionProvider, useSession } from "next-auth/react";
function Session() {
  const { data: session, status } = useSession();
  return <pre>{status}</pre>;
}
export default function App() {
  return <SessionProvider><Session /></SessionProvider>;
}

```

From [example.md](https://next-auth.js.org/getting-started/client)

### Clerk

[GitHub](https://github.com/clerk/javascript) · [npm](https://www.npmjs.com/package/@clerk/react) · [Docs](https://clerk.com/docs/reference/react/overview)

Provides authentication components and user-management hooks for React applications.

- Downloads / mo: 16.8M
- Stars: 1.8K
- Last release: 6.19.0
- License: MIT
- Capabilities: [From the Clerk docs](https://clerk.com/docs/reference/react/overview)

**Strengths**

- **Provides ready-made sign-in controls.** Use prebuilt sign-in and sign-up components for the application.
- **Retrieves session or custom tokens.** Use getToken for the current session or a custom JWT template.

**Watch out for**

- **Requires a Clerk application.** Create a Clerk application and configure its publishable key.
- **Authentication state can reload.** Check isLoaded before depending on the current authentication state.

```sh
npm install @clerk/react
```

**Quickstart**

```jsx
import { ClerkProvider, SignInButton } from "@clerk/react";
export default function App() {
  return <ClerkProvider><SignInButton /></ClerkProvider>;
}

```

From [index.tsx](https://github.com/clerk/clerk-docs/blob/main/docs/getting-started/quickstart.react.mdx) · [Find projects using Clerk →](https://dashboard.exa.ai/playground/search?q=React%20TypeScript%20projects%20using%20%40clerk/react%20for%20sign-in%20forms%2C%20protected%20API%20tokens%2C%20consent%20recovery%20and%20conditional%20authentication%20controls&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### Auth0 React

[GitHub](https://github.com/auth0/auth0-react) · [npm](https://www.npmjs.com/package/@auth0/auth0-react) · [Docs](https://auth0.github.io/auth0-react/)

Connects React single-page applications to Auth0 authentication and authorization.

- Downloads / mo: 8.9M
- Stars: 992
- Last release: 2.30.0
- License: MIT
- Capabilities: [From the Auth0 React docs](https://auth0.github.io/auth0-react/)

**Strengths**

- **Handles protocol and token renewal.** Delegate grant details, token renewal, storage, and caching to the SDK.
- **Exposes authentication through React hooks.** Read user state and invoke login or logout through useAuth0.

**Watch out for**

- **Redirect URLs must be registered.** Register callback, logout, and web origins for the deployed app.
- **Custom routers need redirect handling.** Supply onRedirectCallback when using a custom client router.

```sh
npm install @auth0/auth0-react
```

**auth0-samples/auth0-react-samples** (950 stars)

[auth0-samples/auth0-react-samples](https://github.com/auth0-samples/auth0-react-samples) 

```jsx
export const ExternalApiComponent = () => {
  const { apiOrigin, audience } = getConfig();

  const [state, setState] = useState({
    showResult: false,
    apiMessage: "",
    error: null,
  });

  const { getAccessTokenSilently, loginWithPopup, getAccessTokenWithPopup } =
    useAuth0();

  const handleConsent = async () => {
    try {
      await getAccessTokenWithPopup();
      setState({
        ...state,
        error: null,
      });
    } catch (error) {
      setState({
        ...state,
        error: error.error,
      });
    }

    await callApi();
  };

  const handleLoginAgain = async () => {
    try {
      await loginWithPopup();
      setState({
        ...state,
        error: null,
      });
    } catch (error) {
      setState({
        ...state,
        error: error.error,
      });
    }

    await callApi();
  };

  const callApi = async () => {
    try {
      const token = await getAccessTokenSilently();

      const response = await fetch(`${apiOrigin}/api/external`, {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      });

      const responseData = await response.json();

      setState({
        ...state,
        showResult: true,
        apiMessage: responseData,
      });
    } catch (error) {
      setState({
        ...state,
        error: error.error,
      });
    }
  };

  const handle = (e, fn) => {
    e.preventDefault();
    fn();
  };

  return (
    <>
      <div className="mb-5">
        {state.error === "consent_required" && (
          <Alert variant="warning">
            You need to{" "}
            <a
              href="#/"
              className="alert-link"
              onClick={(e) => handle(e, handleConsent)}
            >
              consent to get access to users api
            </a>
          </Alert>
        )}

        {state.error === "login_required" && (
          <Alert variant="warning">
            You need to{" "}
            <a
              href="#/"
              className="alert-link"
              onClick={(e) => handle(e, handleLoginAgain)}
            >
              log in again
            </a>
          </Alert>
        )}

        <h1>External API</h1>
        <p className="lead">
          Ping an external API by clicking the button below.
        </p>

        <p>
          This will call a local API on port 3001 that would have been started
          if you run <code>npm run dev</code>. An access token is sent as part
          of the request's `Authorization` header and the API will validate it
          using the API's audience value.
        </p>

        {!audience && (
          <Alert variant="warning">
            <p>
              You can't call the API at the moment because your application does
              not have any configuration for <code>audience</code>, or it is
              using the default value of{" "}
              <code>&#123;yourApiIdentifier&#125;</code>. You might get this
              default value if you used the "Download Sample" feature of{" "}
              <a href="https://auth0.com/docs/quickstart/spa/react">
                the quickstart guide
              </a>
              , but have not set an API up in your Auth0 Tenant. You can find
              out more information on{" "}
              <a href="https://auth0.com/docs/api">setting up APIs</a> in the
              Auth0 Docs.
            </p>
            <p>
              The audience is the identifier of the API that you want to call
              (see{" "}
              <a href="https://auth0.com/docs/get-started/dashboard/tenant-settings#api-authorization-settings">
                API Authorization Settings
              </a>{" "}
              for more info).
            </p>

            <p>
              In this sample, you can configure the audience in a couple of
              ways:
            </p>
            <ul>
              <li>
                by exposing the <code>AUTH0_AUDIENCE</code> environment variable to the application
              </li>
              <li>
                by setting <code>AUTH0_AUDIENCE</code> in your <code>.env.local</code> file
                (see <code>.env.example</code> for reference)
              </li>
            </ul>
            <p>
              Once you have configured the value for <code>AUTH0_AUDIENCE</code>,
              please restart the app and try to use the "Ping API" button below.
            </p>
          </Alert>
        )}

        <Button
          variant="primary"
          className="mt-5"
          onClick={callApi}
          disabled={!audience}
        >
          Ping API
        </Button>
      </div>

      <div className="result-block-container">
        {state.showResult && (
          <div className="result-block" data-testid="api-result">
            <h6 className="muted">Result</h6>
            <Highlight>
              <span>{JSON.stringify(state.apiMessage, null, 2)}</span>
            </Highlight>
          </div>
        )}
      </div>
    </>
  );
};

```

[Sample-01/src/views/ExternalApi.jsx](https://github.com/auth0-samples/auth0-react-samples/blob/b58007102474b14fd245e1b857cb95c3b676fb0a/Sample-01/src/views/ExternalApi.jsx#L9-L193) · [More projects using Auth0 React →](https://dashboard.exa.ai/playground/search?q=React%20TypeScript%20projects%20using%20%40auth0/auth0-react%20for%20sign-in%20forms%2C%20protected%20API%20tokens%2C%20consent%20recovery%20and%20conditional%20authentication%20controls&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```jsx
import { Auth0Provider, useAuth0 } from "@auth0/auth0-react";
function Login() {
  const { loginWithRedirect } = useAuth0();
  return <button onClick={() => loginWithRedirect()}>Log in</button>;
}
export default function App() {
  return <Auth0Provider domain="YOUR_AUTH0_DOMAIN" clientId="YOUR_AUTH0_CLIENT_ID"
    authorizationParams={{ redirect_uri: window.location.origin }}><Login /></Auth0Provider>;
}

```

From [README.md](https://github.com/auth0/auth0-react/blob/main/README.md)

### MSAL React

[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-js) · [npm](https://www.npmjs.com/package/@azure/msal-react) · [Docs](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-react)

Integrates Microsoft authentication and token acquisition into React single-page applications.

- Downloads / mo: 7.1M
- Stars: 4.2K
- Last release: 5.8.2
- License: MIT
- Capabilities: [From the MSAL React docs](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-react)

**Strengths**

- **Supports Microsoft account sign-in.** Authenticate work, school, or personal Microsoft accounts.
- **Acquires tokens for Microsoft APIs.** Request tokens to call services such as Microsoft Graph.

**Watch out for**

- **Needs a registered Microsoft app.** Register a client ID and the app’s redirect routes.
- **Hook attempts authentication once.** Call its login or acquireToken method for subsequent attempts.

```sh
npm install @azure/msal-react @azure/msal-browser
```

**Azure-Samples/ms-identity-javascript-react-tutorial** (310 stars)

[Azure-Samples/ms-identity-javascript-react-tutorial](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial) 

```jsx
export const NavigationBar = () => {
    const { instance } = useMsal();

    let activeAccount;

    if (instance) {
        activeAccount = instance.getActiveAccount();
    }

    const handleLoginPopup = () => {
        /**
         * When using popup and silent APIs, we recommend setting the redirectUri to a blank page or a page
         * that does not implement MSAL. Keep in mind that all redirect routes must be registered with the application
         * For more information, please follow this link: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/login-user.md#redirecturi-considerations
         */
        instance
            .loginPopup({
                ...loginRequest,
                redirectUri: '/redirect',
            })
            .catch((error) => console.log(error));
    };

    const handleLoginRedirect = () => {
        instance.loginRedirect(loginRequest).catch((error) => console.log(error));
    };

    const handleLogoutPopup = () => {
        instance
            .logoutPopup({
                mainWindowRedirectUri: '/', // redirects the top level app after logout
                account: instance.getActiveAccount(),
            })
            .catch((error) => console.log(error));
    };

    const handleLogoutRedirect = () => {
        instance.logoutRedirect().catch((error) => console.log(error));
    };

    /**
     * Most applications will need to conditionally render certain components based on whether a user is signed in or not.
     * msal-react provides 2 easy ways to do this. AuthenticatedTemplate and UnauthenticatedTemplate components will
     * only render their children if a user is authenticated or unauthenticated, respectively.
     */
    return (
        <>
            <Navbar bg="primary" variant="dark" className="navbarStyle">
                <a className="navbar-brand" href="/">
                    Microsoft identity platform
                </a>
                <AuthenticatedTemplate>
                    <div className="collapse navbar-collapse justify-content-end">
                        <DropdownButton
                            variant="warning"
                            drop="start"
                            title={activeAccount ? activeAccount.name : 'Unknown'}
                        >
                            <Dropdown.Item as="button" onClick={handleLogoutPopup}>
                                Sign out using Popup
                            </Dropdown.Item>
                            <Dropdown.Item as="button" onClick={handleLogoutRedirect}>
                                Sign out using Redirect
                            </Dropdown.Item>
                        </DropdownButton>
                    </div>
                </AuthenticatedTemplate>
                <UnauthenticatedTemplate>
                    <div className="collapse navbar-collapse justify-content-end">
                        <DropdownButton
                            variant="secondary"
                            className="justify-content-end ml-auto"
                            title="Sign In"
                            drop="start"
                        >
                            <Dropdown.Item as="button" onClick={handleLoginPopup}>
                                Sign in using Popup
                            </Dropdown.Item>
                            <Dropdown.Item as="button" onClick={handleLoginRedirect}>
                                Sign in using Redirect
                            </Dropdown.Item>
                        </DropdownButton>
                    </div>
                </UnauthenticatedTemplate>
            </Navbar>
        </>
    );
};

```

[1-Authentication/1-sign-in/SPA/src/components/NavigationBar.jsx](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/blob/381714b6576fa987ecf5ea664472f9eee6a5b866/1-Authentication/1-sign-in/SPA/src/components/NavigationBar.jsx#L5-L92) · [More projects using MSAL React →](https://dashboard.exa.ai/playground/search?q=React%20TypeScript%20projects%20using%20%40azure/msal-react%20for%20sign-in%20forms%2C%20protected%20API%20tokens%2C%20consent%20recovery%20and%20conditional%20authentication%20controls&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```jsx
import { PublicClientApplication } from "@azure/msal-browser";
import { MsalProvider, useMsal } from "@azure/msal-react";
const pca = new PublicClientApplication({ auth: { clientId: "client-id" } });
function Login() {
  const { instance } = useMsal();
  return <button onClick={() => instance.loginPopup()}>Login</button>;
}
export default function App() { return <MsalProvider instance={pca}><Login /></MsalProvider>; }

```

From [getting-started.md](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/README.md)

### @react-oauth/google

[GitHub](https://github.com/MomenSherif/react-oauth) · [npm](https://www.npmjs.com/package/@react-oauth/google)

Adds Google OAuth sign-in to React through Google Identity Services.

- Downloads / mo: 6.5M
- Stars: 1.3K
- Last release: 0.13.5
- License: MIT
- Capabilities: [From the @react-oauth/google docs](https://github.com/MomenSherif/react-oauth)

```sh
npm install @react-oauth/google
```

**Quickstart**

```tsx
import { GoogleOAuthProvider, GoogleLogin } from '@react-oauth/google';

function App() {
  return (
    <GoogleOAuthProvider clientId="<your_client_id>">
      <GoogleLogin
        onSuccess={credentialResponse => {
          console.log(credentialResponse);
        }}
        onError={() => {
          console.log('Login Failed');
        }}
      />
    </GoogleOAuthProvider>
  );
}

```

From [README.md](https://github.com/MomenSherif/react-oauth/blob/master/README.md) · [Find projects using @react-oauth/google →](https://dashboard.exa.ai/playground/search?q=%40react-oauth/google%20GitHub%20projects)

### react-oidc-context

[GitHub](https://github.com/authts/react-oidc-context) · [npm](https://www.npmjs.com/package/react-oidc-context)

Provides OpenID Connect and OAuth authentication with React context for state management.

- Downloads / mo: 4.2M
- Stars: 1.0K
- Last release: 3.3.1
- License: MIT
- Capabilities: [From the react-oidc-context docs](https://github.com/authts/react-oidc-context)

```sh
npm install oidc-client-ts react-oidc-context --save
```

**Quickstart**

```tsx
import { AuthProvider, useAuth } from "react-oidc-context";
function Login() {
  const auth = useAuth();
  return <button onClick={() => void auth.signinRedirect()}>Log in</button>;
}
export default function App() {
  return <AuthProvider authority="https://issuer.example.com" client_id="client-id"
    redirect_uri={window.location.origin}><Login /></AuthProvider>;
}

```

From [README.md](https://github.com/authts/react-oidc-context/blob/main/README.md) · [Find projects using react-oidc-context →](https://dashboard.exa.ai/playground/search?q=react-oidc-context%20GitHub%20projects)

### @workos-inc/authkit-react

[GitHub](https://github.com/workos/authkit-react) · [npm](https://www.npmjs.com/package/@workos-inc/authkit-react)

Provides the AuthKit React SDK.

- Downloads / mo: 2.3M
- Stars: 48
- Last release: 0.16.3
- License: MIT
- Capabilities: [From the @workos-inc/authkit-react docs](https://github.com/workos/authkit-react)

```sh
npm install @workos-inc/authkit-react
```

**Quickstart**

```tsx
import { AuthKitProvider, useAuth } from "@workos-inc/authkit-react";
function Login() {
  const { signIn } = useAuth();
  return <button onClick={() => signIn()}>Sign in</button>;
}
export default function App() {
  return <AuthKitProvider clientId="client_01ABC123DEF456"><Login /></AuthKitProvider>;
}

```

From [README.md](https://github.com/workos/authkit-react/blob/main/README.md) · [Find projects using @workos-inc/authkit-react →](https://dashboard.exa.ai/playground/search?q=%40workos-inc/authkit-react%20GitHub%20projects)

## FAQ

### Which React authentication library should I use?

[NextAuth.js](#nextauth-js) suits Next.js apps that configure sign-in providers in their own authentication route. [Clerk](#clerk-react) suits apps that want prebuilt sign-in components on a hosted Clerk application. [MSAL React](#msal-react) suits apps that sign in Microsoft work, school, or personal accounts.

### What is Better Auth?

[Better Auth](#better-auth) is an authentication framework for TypeScript.

### What is NextAuth.js?

[NextAuth.js](#nextauth-js) connects React session controls to authentication configured in a Next.js application. Its callbacks choose which extra session fields reach the browser.

### How do I sign users in with Auth0 React?

[Auth0 React](#auth-react) exposes user state, login, and logout through a React hook. The app's callback, logout, and web origin URLs must be registered with the identity provider.

### What is Clerk for React?

[Clerk](#clerk-react) provides authentication components and user-management hooks for React. It requires a Clerk application with a publishable key.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best React authentication libraries NextAuth Clerk Auth0 MSAL code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
