Server 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.
Authentication
signInAction()
Start the sign-in flow. By default, redirects the user to the ThunderID sign-in page. Optionally accepts parameters for embedded sign-in flows.
import { signInAction } from '@thunderid/nextjs/server'
// Redirect-based sign-in (default)
await signInAction()
// With embedded flow payload (advanced)
await signInAction(payload, requestConfig)
| Parameter | Type | Description |
|---|---|---|
payload | EmbeddedSignInFlowHandleRequestPayload | Optional payload for embedded sign-in flows |
requestConfig | EmbeddedFlowExecuteRequestConfig | Optional request configuration for embedded flows |
signOutAction()
Sign out the current user and clear the session cookie.
import { signOutAction } from '@thunderid/nextjs/server'
await signOutAction()
signUpAction()
Start the sign-up flow.
import { signUpAction } from '@thunderid/nextjs/server'
await signUpAction()
refreshToken()
Manually refresh the access token.
import { refreshToken } from '@thunderid/nextjs/server'
const result = await refreshToken()
// result.expiresAt — token expiry timestamp
Returns: Promise<{ expiresAt: number }>
Session
isSignedIn()
Check whether the current user is authenticated.
import { isSignedIn } from '@thunderid/nextjs/server'
const authenticated = await isSignedIn()
Returns: Promise<boolean>
getSessionId()
Retrieve the current session ID.
import { getSessionId } from '@thunderid/nextjs/server'
const sessionId = await getSessionId()
Returns: Promise<string | undefined>
getSessionPayload()
Retrieve the full session token payload including user ID, scopes, and organization.
import { getSessionPayload } from '@thunderid/nextjs/server'
const session = await getSessionPayload()
if (session) {
console.log(session.sub, session.scopes)
}
Returns: Promise<SessionTokenPayload | undefined>
getAccessToken()
Retrieve the current access token for making authenticated API calls from the server.
import { getAccessToken } from '@thunderid/nextjs/server'
const token = await getAccessToken()
Returns: Promise<string | undefined>
clearSession()
Clear the session cookie without triggering a sign-out flow.
import { clearSession } from '@thunderid/nextjs/server'
await clearSession()
User Management
getUserAction()
Retrieve the authenticated user's profile.
import { getUserAction, getSessionId } from '@thunderid/nextjs/server'
const sessionId = await getSessionId()
const result = await getUserAction(sessionId)
if (result.success) {
console.log(result.data.user)
}
Returns: Promise<{ data: { user: User | null }; error: string | null; success: boolean }>
getUserProfileAction()
Retrieve the extended user profile with SCIM2 schema details.
import { getUserProfileAction, getSessionId } from '@thunderid/nextjs/server'
const sessionId = await getSessionId()
const result = await getUserProfileAction(sessionId)
if (result.success) {
console.log(result.data.userProfile)
}
updateUserProfileAction()
Update the current user's profile.
import { updateUserProfileAction } from '@thunderid/nextjs/server'
const result = await updateUserProfileAction({
name: { givenName: 'Jane', familyName: 'Doe' },
})
Organization Management
getMyOrganizations()
List organizations the current user belongs to.
import { getMyOrganizations } from '@thunderid/nextjs/server'
const organizations = await getMyOrganizations()
switchOrganization()
Switch the current session to a different organization.
import { switchOrganization } from '@thunderid/nextjs/server'
await switchOrganization(targetOrganization)
createOrganization()
Create a new organization.
import { createOrganization } from '@thunderid/nextjs/server'
const org = await createOrganization({ name: 'Acme Corp' })
getAllOrganizations()
List all organizations (requires admin privileges).
import { getAllOrganizations } from '@thunderid/nextjs/server'
const response = await getAllOrganizations()
getCurrentOrganizationAction()
Retrieve the organization for the current session.
import { getCurrentOrganizationAction, getSessionId } from '@thunderid/nextjs/server'
const sessionId = await getSessionId()
const result = await getCurrentOrganizationAction(sessionId)
thunderid() Client Access
For advanced use cases, access the server-side client directly:
import { thunderid } from '@thunderid/nextjs/server'
const client = await thunderid()
const token = await client.getAccessToken(sessionId)
const result = await client.exchangeToken(config, sessionId)
| Method | Description |
|---|---|
getAccessToken(sessionId) | Retrieve the access token for a session |
getSessionId() | Retrieve the current session ID |
exchangeToken(config, sessionId) | Perform a custom token exchange |
reInitialize(config) | Update SDK configuration at runtime |