Skip to main content

getThunderIDContext()

get<ProductName />Context returns the ThunderID context object that the SDK's server plugin attaches to each H3 event during SSR. This gives synchronous access to the session and pre-fetched SSR data without an additional async call.

Signature

getThunderIDContext(event: H3Event): ThunderIDEventContext | null

Import

import { getThunderIDContext } from '@thunderid/nuxt/server'

Usage

Reading Auth State Synchronously

server/api/status.get.ts
import { getThunderIDContext } from '@thunderid/nuxt/server'

export default defineEventHandler((event) => {
const ctx = getThunderIDContext(event)

return {
isSignedIn: ctx?.isSignedIn ?? false,
sub: ctx?.session?.sub ?? null,
}
})

Accessing SSR Data

server/api/init.get.ts
import { getThunderIDContext } from '@thunderid/nuxt/server'

export default defineEventHandler((event) => {
const ctx = getThunderIDContext(event)

return {
user: ctx?.ssr?.user ?? null,
organizations: ctx?.ssr?.myOrganizations ?? [],
}
})

Return Value

Returns ThunderIDEventContext | null. Returns null when the server plugin has not run (e.g., in routes that execute before the plugin).

ThunderIDEventContext

PropertyTypeDescription
isSignedInbooleanWhether the request is authenticated
sessionThunderIDSessionPayload | nullThe decoded session payload, or null
ssrThunderIDSSRData | undefinedPre-fetched SSR data (user, orgs, branding), if populated

ThunderIDSSRData

PropertyTypeDescription
isSignedInbooleanWhether the user is signed in
sessionThunderIDSessionPayload | nullThe session payload
userUser | nullThe authenticated user object
userProfileUserProfile | nullThe user's profile
currentOrganizationOrganization | nullThe active organization from the session
myOrganizationsOrganization[]All organizations the user belongs to
brandingPreferenceBrandingPreference | nullThe tenant's branding preference
resolvedBaseUrlstring | nullThe resolved ThunderID base URL

Notes

  • getThunderIDContext is synchronous: it reads data that was attached to the event by the server plugin earlier in the request lifecycle.
  • For routes where the plugin may not have run, fall back to useServerSession().
  • The ssr field is only populated when SSR data-fetching is enabled in preferences (it is enabled by default).

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.