Skip to main content

Next.js SDK

The ThunderID Next.js SDK (@thunderid/nextjs) provides server-side authentication, middleware-based route protection, and pre-built UI components for Next.js applications using the App Router.

Installation

Install the ThunderID Next.js SDK using your preferred package manager:

npm install @thunderid/nextjs

Getting Started

To get started quickly, check out our Next.js Quickstart Guide for step-by-step instructions.

Architecture

The Next.js SDK uses a server-first approach:

  • Authentication tokens are stored in HttpOnly cookies, preventing client-side access
  • Token refresh happens automatically in middleware before requests reach your pages
  • Server Actions handle sign-in, sign-out, and user operations without exposing tokens
  • Pre-built components from @thunderid/react are available for client-side UI

Features

Server Exports

Middleware (@thunderid/nextjs/server)

Client Components (@thunderid/nextjs)

Action Components

  • <SignInButton />: Trigger sign-in flow
  • <SignOutButton />: Sign out the current user
  • <SignUpButton />: Trigger sign-up flow

Control Components

  • <SignedIn />: Conditionally render content for authenticated users
  • <SignedOut />: Conditionally render content for unauthenticated users

User Self-Care Components

  • <UserDropdown />: User menu with profile and settings
  • <UserProfile />: Complete user profile management interface
  • <User />: Display user information

Organization Components (B2B)

  • <CreateOrganization />: Create new organizations
  • <OrganizationProfile />: Manage organization settings
  • <OrganizationSwitcher />: Switch between organizations
  • <OrganizationList />: List user's organizations

Hooks

  • useThunderID(): Access authentication state and methods from client components

Environment Variables

VariableRequiredDescription
NEXT_PUBLIC_THUNDERID_BASE_URLYesYour ThunderID instance URL
NEXT_PUBLIC_THUNDERID_CLIENT_IDYesThe Client ID from your application
THUNDERID_CLIENT_SECRETYesThe Client Secret (server-side only)
THUNDERID_SECRETProductionSecret for signing session cookies (at least 32 characters)
THUNDERID_SESSION_COOKIE_EXPIRY_TIMENoCookie lifetime in seconds (default: 86400)

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.