Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Type Alias

Session

Session is Better Auth's inferred TypeScript type for the current session response. It includes both the session object and its associated user object, with configured extensions reflected in the type.

How it works

Session is an inferred TypeScript type exposed through Better Auth's $Infer property. It describes an object containing both the session record and the associated user object, with plugin-added fields included when applicable.

Syntax

type Session = typeof authClient.$Infer.Session

Returns

An inferred object type with session and user properties, reflecting configured and plugin-provided fields.

Key points

  • Infer Session from either the client SDK or the server auth instance through $Infer.
  • Plugin extensions to User and Session participate in the inferred type.
  • The result separates the user object from the session object under user and session.
  • Server code can derive Session from the Better Auth server instance, not only from a client.

Common mistakes

  • Use Session as a wrapper containing both related objects; it is not only the database session record.

Example: Infer the Session type

import { createAuthClient } from "better-auth/client"

const authClient = createAuthClient()
export type Session = typeof authClient.$Infer.Session

const session: Session = await authClient.getSession()
console.log(session.session, session.user)

This derives the client-side Session type from the configured Better Auth client and uses it for session data.

When to use it

Type session data returned by the client

Client session state

Infer the session shape from the server auth instance

Server request handling

Carry plugin-added user or session fields through application types

Plugin-enabled applications

Interview questions

QHow do you infer the Session type on the client?

Use the client instance's $Infer property: type Session = typeof authClient.$Infer.Session. The resulting type contains both session and user properties.

Follow-up: How can server-side code infer the same type? Define the server auth instance and use typeof auth.$Infer.Session.

QWhat does the inferred Session type contain?

The user member represents the user object type, while session represents the session object type. This lets application code type both parts of the returned session data.

Follow-up: What should happen when a plugin adds fields? The inferred type should include plugin-provided extensions.

QWhy prefer $Infer.Session over a handwritten interface?

Plugins can extend the base User and Session types, and those additions are available through $Infer. Therefore, deriving the type from the configured client or server instance keeps it aligned with the active setup.

Follow-up: How would you avoid stale manually duplicated interfaces? Infer the type directly from the configured Better Auth instance.

  • User
  • $Infer
  • createAuthClient
  • Session Management
  • getSession

Source: TypeScript. Checked 2026-10-15.