API reference
The public surface of
@thunderid/node, as documented in its reference pages.ThunderIDNodeClient`ThunderIDNodeClient` is an abstract base class that extends `ThunderIDJavaScriptClient` with Node.js-specific configuration. Use this class as the foundation when building a new framework-specific authentication client for a Node.js runtime. Examples include adapters for other Node.js server frameworks.
import { ThunderIDNodeClient, ThunderIDNodeConfig } from '@thunderid/node'
interface MyFrameworkConfig extends ThunderIDNodeConfig {
customOption?: string
}
class MyFrameworkClient extends ThunderIDNodeClient<MyFrameworkConfig> {
// Add framework-specific methods or override inherited ones here
}
export default MyFrameworkClientThunderIDNodeConfig`ThunderIDNodeConfig` is the configuration type for the ThunderID Node.js SDK. The type extends the base `Config` from `@thunderid/javascript` and adds a Node.js-specific option for controlling session cookie lifetime.
import { ThunderIDNodeConfig } from '@thunderid/node'
const config: ThunderIDNodeConfig = {
clientId: '<your-client-id>',
serverOrigin: 'https://localhost:8090',
afterSignInUrl: 'http://localhost:3000/callback',
afterSignOutUrl: 'http://localhost:3000',
sessionCookieExpiryTime: 28800, // 8 hours
}CookieConfig`CookieConfig` is a constants class that exposes the default values used for session cookie configuration in the ThunderID Node.js SDK. Use these constants when setting cookies for session management or when passing options to `getSessionCookieOptions`.
import { CookieConfig } from '@thunderid/node'
// Use the default session cookie name
res.cookie(CookieConfig.SESSION_COOKIE_NAME, sessionId, {
httpOnly: CookieConfig.DEFAULT_HTTP_ONLY,
maxAge: CookieConfig.DEFAULT_MAX_AGE * 1000, // convert to milliseconds
sameSite: CookieConfig.DEFAULT_SAME_SITE,
secure: CookieConfig.DEFAULT_SECURE,
})CookieOptions`CookieOptions` defines the shape of cookie configuration options used in the ThunderID Node.js SDK. Pass a `CookieOptions` object to `getSessionCookieOptions` to override the default cookie settings.
interface CookieOptions {
httpOnly?: boolean
maxAge?: number
sameSite?: boolean | 'lax' | 'strict' | 'none'
secure?: boolean
}generateSessionId()`generateSessionId` generates a unique session identifier string. Use this utility to create a new session ID when a user signs in and store the value in a cookie or server-side session store.
import { generateSessionId, CookieConfig, getSessionCookieOptions } from '@thunderid/node'
app.get('/sign-in', (req, res) => {
const sessionId = generateSessionId()
res.cookie(
CookieConfig.SESSION_COOKIE_NAME,
sessionId,
getSessionCookieOptions({ maxAge: 3600 }),
)
auth.signIn(
(authUrl) => res.redirect(authUrl),
sessionId,
)
})getSessionCookieOptions()`getSessionCookieOptions` merges the provided partial `CookieOptions` with the default values from `CookieConfig`. Any property you omit falls back to its default.
optionsrequiredPartialCookie options to apply. Unspecified properties use the defaults from `CookieConfig`.
import { getSessionCookieOptions } from '@thunderid/node'
// Override only maxAge; all other properties use defaults
const options = getSessionCookieOptions({ maxAge: 86400 }) // 24 hours