Skip to main content
Better Auth is designed from the ground up to be fully type-safe. Both the server instance and the client SDK expose types that reflect your exact configuration, including any plugins or extra fields you add. Better Auth requires strictNullChecks to be enabled for type inference to work correctly. The easiest way to ensure this is to enable strict mode:
tsconfig.json
If you cannot enable strict, enable strictNullChecks explicitly:
tsconfig.json
If you run into “type instantiation is excessively deep” errors, make sure declaration and composite are not enabled in your tsconfig.json, in addition to following the settings above.

Inferring types with $Infer

Both the server instance and the client expose an $Infer namespace. Plugins can extend base types like User and Session, and those extensions flow through automatically.

Server-side

auth.ts

Client-side

auth-client.ts

Additional fields

You can add extra fields to the user and session tables. All additional fields are fully typed on both the server and client.
auth.ts

The input property

Additional fields default to input: true, meaning clients can provide a value during sign-up. Always set input: false for sensitive fields like role or banned that should only be set server-side.

Inferring additional fields on the client

The client needs to know about server-side additional fields for its types to match. There are two approaches depending on your project structure.

Same project (monorepo or single repo)

Use the inferAdditionalFields plugin and pass your server auth type:
auth-client.ts

Separate client and server projects

Specify the fields manually when creating the client:
auth-client.ts

Plugin type inference

Plugins extend User, Session, and other types transparently. Install a plugin on the server and its types automatically propagate through $Infer.
auth.ts
For client plugins, use the $InferServerPlugin helper to mirror the server plugin’s types:
client.ts

useSession type inference

The useSession hook (React, Vue, Svelte, Solid) returns the same inferred Session type: