Tesseral React SDK
Add B2B auth support to your clientside React app in just a few lines of code.
If this is your first time using the Tesseral React SDK, we recommend following the Tesseral Quickstart.
Tesseral’s React SDK lets you add B2B auth support to your clientside React app.
Getting Started
Install the Tesseral React SDK by running:
Then, in your React application, add a TesseralProvider
at the root of your
React application:
Replace publishable_key_...
with your project’s Publishable Key. You can find
it in the API Keys
Settings of the
Tesseral Console.
You’ll need to use a separate Publishable Key for development and production.
It’s up to you how to pass a different publishableKey
for dev vs prod.
In development, make sure you’re using a Publishable Key that has “Dev Mode” enabled.
Once you’ve added TesseralProvider
, all visitors to your React app will
automatically be authenticated. Unauthenticated visitors are redirected to a
Tesseral-hosted login flow before being redirected back to your application.
Accessing details about the authenticated user
The Tesseral React SDK makes information about your authenticated user available through a set of React hooks.
Tesseral’s React SDK hooks will throw an error if used outside of a child
component of TesseralProvider
.
useUser
To get the current logged-in User, call useUser
:
useOrganization
To get the Organization that the User works for,
call useOrganization
:
useLogout
To force the current User to log out, call the callback returned from
useLogout
:
useUserSettingsUrl
Tesseral automatically provides a self-serve user settings UI to handle tasks like changing emails, resetting passwords, and configuring multi-factor authentication.
You can get a link to that UI using useUserSettingsUrl
:
useOrganizationSettingsUrl
Tesseral automatically provides a self-serve organization settings UI to handle tasks like managing collaborators, creating and revoking user invites, and customizing login methods.
You can get a link to that UI using useOrganizationSettingsUrl
:
useAccessToken
Most folks never need to use useAccessToken
, because Tesseral automatically
sets an authentication cookie on your visitor’s browsers.
To directly access the User’s access token, call useAccessToken
:
Advanced Usage
Tesseral provides polished, self-serve UIs for user and organization settings on
your behalf, which you can redirect your users to using useUserSettingsUrl
and
useOrganizationSettingsUrl
.
Everything those prebuilt UIs do, you can also do from your own clientside code. Doing so is an advanced feature, and is not required.
For details on how to do this, see the documentation for the Tesseral Frontend API.