© 2026 Hedgehog Software, LLC
import type { Session } from 'next-auth' type CreateContextOptions = { session: Session | null }
getAuth
userId
SignedInAuthObject
export const createTRPCContext = async (opts: CreateNextContextOptions) => { // Get the session from the server using the getServerSession wrapper function const session = getAuth(opts.req) const { userId } = session if (!userId) return createInnerTRPCContext({ session }) const user = await clerkClient.users.getUser(userId) const orgs = await clerkClient.users.getOrganizationMembershipList({ userId }) return createInnerTRPCContext({ session, user, orgSlug: orgs[0]?.organization?.slug, }) }