Skip to main content
Back to Next.js

Configuration

The ThunderID Next.js SDK reads configuration primarily from environment variables. This keeps secrets out of your source code and follows Next.js conventions.

Environment Variables

Create a .env file in your project root:

.env
NEXT_PUBLIC_THUNDERID_BASE_URL=https://localhost:8090
NEXT_PUBLIC_THUNDERID_CLIENT_ID=<your-client-id>
THUNDERID_CLIENT_SECRET=<your-client-secret>
THUNDERID_SECRET=<a-random-secret-for-session-signing>

Required Variables

VariableDescription
NEXT_PUBLIC_THUNDERID_BASE_URLYour ThunderID instance URL. The NEXT_PUBLIC_ prefix makes this available to client components
NEXT_PUBLIC_THUNDERID_CLIENT_IDThe Client ID from your ThunderID application
THUNDERID_CLIENT_SECRETThe Client Secret from your ThunderID application. Server-side only, never exposed to the browser
THUNDERID_SECRETA random string (at least 32 characters) used to sign session cookies with HMAC-SHA256. Required in production; a development fallback is used when not set

Optional Variables

VariableDefaultDescription
THUNDERID_SESSION_COOKIE_EXPIRY_TIME86400Session cookie lifetime in seconds (24 hours by default)

Session Cookies

The SDK stores authentication state in signed, HttpOnly cookies:

CookiePurposeLifetime
Session cookieStores access token, refresh token, user ID, and scopesConfigured via THUNDERID_SESSION_COOKIE_EXPIRY_TIME
Temporary session cookieHolds state during the OAuth flow15 minutes
SettingValueDescription
httpOnlytruePrevents client-side JavaScript access
securetrue (production)Requires HTTPS in production
sameSitelaxProtects against CSRF while allowing navigation
path/Available to all routes

Application Configuration

Beyond environment variables, you can pass additional configuration to the ThunderIDProvider:

app/layout.tsx
import { ThunderIDProvider } from '@thunderid/nextjs/server'

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<ThunderIDProvider sessionCookieExpiryTime={3600}>
{children}
</ThunderIDProvider>
</body>
</html>
)
}

Key Differences from the React SDK

AspectReact SDKNext.js SDK
Token storageBrowser storage (sessionStorage, localStorage)HttpOnly cookies (server-managed)
Client typePublic client (no secret)Confidential client (with secret)
PKCERequiredNot required (confidential client)
Token refreshClient-initiatedAutomatic in middleware
ConfigurationProps on ThunderIDProviderEnvironment variables

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.