Skip to main content
Back to Express

ThunderIDExpressClient

ThunderIDExpressClient is the Express-aware client class exported by @thunderid/express. It extends ThunderIDNodeClient and adds Express-specific request and configuration access.

Import

const {ThunderIDExpressClient} = require('@thunderid/express');

Overview

In most applications, you do not instantiate this class directly. The thunderID() middleware creates and initializes it for you, then attaches it to req.thunderIDAuth and res.thunderIDAuth.

Express-Specific Members

expressConfig

Returns the initialized ExpressClientConfig value or undefined if the client has not been initialized yet.

MemberTypeDescription
expressConfigExpressClientConfig | undefinedThe Express SDK configuration used to initialize the client

getUserFromRequest(req)

Reads the session ID from req.cookies[SESSION_COOKIE_NAME] and returns the current user for that session.

getUserFromRequest(req: express.Request): Promise<User | undefined>
index.js
app.get('/me', async (req, res) => {
const user = await req.thunderIDAuth.getUserFromRequest(req);
res.json(user);
});

updateUserCredentialsFromRequest(req, payload)

Reads the session ID from req.cookies[SESSION_COOKIE_NAME] and updates that session's credentials, for example password, or any other attribute the user type schema declares credential: true.

updateUserCredentialsFromRequest(req: express.Request, payload: Record<string, string>): Promise<void>
index.js
app.use(express.json());

app.patch('/me/credentials', async (req, res) => {
await req.thunderIDAuth.updateUserCredentialsFromRequest(req, req.body);
res.status(204).end();
});

Returns: Promise<void> - The underlying endpoint responds with 204 No Content on success. Throws ThunderIDAPIError on failure.

Inherited Behavior

Because ThunderIDExpressClient extends ThunderIDNodeClient, inherited Node client methods are also available. This Express SDK section does not provide a full reference for the inherited Node surface.

Notes

  • getUserFromRequest(req) and updateUserCredentialsFromRequest(req, payload) both depend on req.cookies, so mount cookie-parser before routes that use them
  • updateUserCredentialsFromRequest(req, payload) also depends on req.body, so mount express.json() (or another body parser) before routes that use it
  • signIn() and signOut() are also overridden internally to integrate with Express request and response handling, but this page focuses on the public Express-specific additions

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.