Tesseral for Express.js
Tesseral’s Express SDK lets you add authentication to your Express.js backend.
The Tesseral Express SDK is open-source and available on GitHub.
Getting Started
Install the Tesseral Express SDK by running:
Then, in the file where you create your Express server, apply the requireAuth
middleware:
Replace publishable_key_...
with your project’s Publishable Key. You can find
it in the API Keys
Settings of the
Tesseral Console.
Once you’ve added requireAuth
, all HTTP requests to your server will be
authenticated. Inauthentic requests will receive a 401 Unauthorized
error
before they reach your route handlers.
Accessing details about the authenticated request
The Tesseral middleware attaches information about the authenticated request
directly to req
. Use the helper functions from @tesseral/tesseral-express
to
access this data.
Getting the current Organization
To access the Organization the request is for, use organizationId(req)
:
This is the most common identifier you’ll use in a B2B SaaS application.
Getting the request’s authenticated credentials
Anywhere your code wants to forward along the request’s credentials, use
credentials(req)
:
Do not log or expose this value. You usually don’t need to use this unless you’re building internal service-to-service calls.
Getting details about the current User
To access extra details about the authenticated User, use
accessTokenClaims(req)
:
accessTokenClaims
returns an
AccessTokenClaims
,
which contains details about the current Session ID, User, and Organization.
If the request if from an API Key, then
accessTokenClaims
will throw a NotAnAccessTokenError
.
We recommend that you mostly use organizationId(req)
in the vast majority of
your code; that is almost always the correct piece of information for most B2B
SaaS code should pay attention to. For more details, see B2B
Multitenancy.