API reference
The public surface of
@thunderid/nextjs, as documented in its reference pages.<ThunderIDProvider />The `ThunderIDProvider` is a React Server Component that initializes ThunderID authentication and wraps your application layout. It manages server-side session state and provides authentication context to all child components.
childrenReactNode**Required.** Your application tree
sessionCookieExpiryTimenumberSession cookie lifetime in seconds. Also configurable via the `THUNDERID_SESSION_COOKIE_EXPIRY_TIME` environment variable
import { ThunderIDProvider } from '@thunderid/nextjs/server'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<ThunderIDProvider>
{children}
</ThunderIDProvider>
</body>
</html>
)
}ConfigurationThe ThunderID Next.js SDK reads configuration primarily from environment variables. This keeps secrets out of your source code and follows Next.js conventions.
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>
MiddlewareThe ThunderID Next.js SDK provides Edge Runtime-compatible middleware for automatic token refresh and route protection.
import {
thunderIDProxy,
createRouteMatcher,
} from '@thunderid/nextjs/server'
const isProtectedRoute = createRouteMatcher(['/dashboard(.*)'])
export default thunderIDProxy(async (thunderid, request) => {
if (isProtectedRoute(request)) {
await thunderid.protectRoute()
}
})
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}Server ActionsThe ThunderID Next.js SDK provides server actions for authentication, session management, and user operations. These run only on the server and never expose tokens to the client. Import all server actions from `@thunderid/nextjs/server`.
import { signInAction } from '@thunderid/nextjs/server'
// Redirect-based sign-in (default)
await signInAction()
// With embedded flow payload (advanced)
await signInAction(payload, requestConfig)