Skip to main content

API reference

The public surface of

@thunderid/nextjs, as documented in its reference pages.

function<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.

Props
children
ReactNode

**Required.** Your application tree

sessionCookieExpiryTime
number

Session cookie lifetime in seconds. Also configurable via the `THUNDERID_SESSION_COOKIE_EXPIRY_TIME` environment variable

Example
import { ThunderIDProvider } from '@thunderid/nextjs/server'

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

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

Example
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>
functionMiddleware

The ThunderID Next.js SDK provides Edge Runtime-compatible middleware for automatic token refresh and route protection.

Example
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).*)'],
}
functionServer Actions

The 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`.

Example
import { signInAction } from '@thunderid/nextjs/server'

// Redirect-based sign-in (default)
await signInAction()

// With embedded flow payload (advanced)
await signInAction(payload, requestConfig)
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.