Express API reference
Every export is fully typed. The signatures and props below come from the package's own reference documentation, so what is listed here is what the installed version ships.
Middleware
ThunderID Middleware
middleware
The thunderID() function returns Express middleware that initializes a ThunderIDExpressClient and attaches it to both req.thunderIDAuth and res.thunderIDAuth.
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignIn, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(
thunderID({
baseUrl: 'https://<DATA_PLANE_URL>',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
}),
);
app.get('/login', handleSignIn());
app.get('/logout', handleSignOut());
handleFlow()
middleware
The handleFlow() function returns an Express route handler that advances the embedded sign-in flow and responds with JSON.
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleFlow, handleSignIn, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(
thunderID({
baseUrl: 'https://<DATA_PLANE_URL>',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
mode: 'embedded',
}),
);
app.post('/flow/sign-in', handleFlow());
app.get('/login', handleSignIn());
app.get('/logout', handleSignOut());
handleSignIn()
middleware
The handleSignIn() function returns an Express route handler for the sign-in path.
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignIn} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(
thunderID({
baseUrl: 'https://<DATA_PLANE_URL>',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignInUrl: 'http://localhost:3000/login',
}),
);
app.get('/login', handleSignIn());
handleSignOut()
middleware
The handleSignOut() function returns an Express route handler for the sign-out path.
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(
thunderID({
baseUrl: 'https://<DATA_PLANE_URL>',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignOutUrl: 'http://localhost:3000/logout',
}),
);
app.get('/logout', handleSignOut());
protect()
middleware
The protect() function returns Express middleware that blocks unauthenticated requests.
const {protect} = require('@thunderid/express');
app.get('/protected', protect(), (_req, res) => {
res.send('Protected content');
});
Client
ThunderIDExpressClient
class
ThunderIDExpressClient is the Express-aware client class exported by @thunderid/express. It extends ThunderIDNodeClient and adds Express-specific request and configuration access.
const {ThunderIDExpressClient} = require('@thunderid/express');
Configuration
ExpressClientConfig
export
ExpressClientConfig is the main configuration type for @thunderid/express.
const {thunderID} = require('@thunderid/express');
app.use(
thunderID({
baseUrl: 'https://<DATA_PLANE_URL>',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignInUrl: 'http://localhost:3000/login',
afterSignOutUrl: 'http://localhost:3000/logout',
sessionCookie: {
expiryTime: 28800,
httpOnly: true,
sameSite: 'lax',
secure: false,
},
}),
);
Constants
CookieConfig
export
The Express SDK exports CookieConfig and SESSION_COOKIE_NAME for the session cookie behavior used by the SDK.
const {SESSION_COOKIE_NAME} = require('@thunderid/express');
app.get('/session-id', (req, res) => {
res.json({sessionId: req.cookies?.[SESSION_COOKIE_NAME] ?? null});
});
Was this page helpful?