Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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
Better Auth has the most monthly downloads in this comparison, at 72.7M.
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>{yourApiIdentifier}</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>
</>
);
};
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
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.
Limitations
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.
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>
</>
);
};
@react-oauth/google
Adds Google OAuth sign-in to React through Google Identity Services.
NextAuth.js suits Next.js apps that configure sign-in providers in their own authentication route. Clerk suits apps that want prebuilt sign-in components on a hosted Clerk application. MSAL React suits apps that sign in Microsoft work, school, or personal accounts.
Better Auth is an authentication framework for TypeScript.
NextAuth.js connects React session controls to authentication configured in a Next.js application. Its callbacks choose which extra session fields reach the browser.
Auth0 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.
Clerk provides authentication components and user-management hooks for React. It requires a Clerk application with a publishable key.
For coding agents
Found your authentication library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.