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

Better Auth · Type Alias

User

Better Auth’s User type is the inferred shape of an authenticated user object. Plugins and configured additional fields can extend it, with the resulting type available across server and client code.

How it works

Better Auth’s User type represents the authenticated user object returned with a session. Its shape can be extended by plugins and configured additional user fields, while the TypeScript inference system makes the resulting type available through the inferred API types.

Syntax

type User = /* inferred Better Auth user object */

Returns

The inferred authenticated user object shape, including fields contributed by plugins and configured additional fields.

Key points

  • A session separates identity data under user from session metadata under session.
  • Installed plugins may add properties to the User type.
  • Use $Infer to obtain the User shape generated by the configured authentication system.
  • Configuration supports custom fields on both user and session records.
  • Declared custom fields remain type-safe across server and client code.

Common mistakes

  • Plugin-provided fields can change the effective User shape, so prefer Better Auth’s inference utilities instead of manually duplicating the type.
  • Additional user fields must be declared through the supported configuration so both server and client types include them.

Example: Access the inferred user shape

import { betterAuth } from "better-auth";

const auth = betterAuth({
  user: {
    additionalFields: {
      plan: { type: "string", defaultValue: "free" }
    }
  }
});

const session = await auth.api.getSession({
  headers: new Headers()
});

const user = session?.user;

The inferred session user exposes the configured user shape, including fields added through the user configuration.

When to use it

Session-aware application code

Reading the authenticated identity from a session response.

End-to-end type safety

Sharing user properties between frontend and backend without manually duplicating interfaces.

Extensible user models

Adding plugin or application-specific user properties while retaining inference.

Interview questions

QWhat does Better Auth’s User type represent?

The User type describes the user object associated with an authenticated session. Better Auth can extend it with plugin fields and configured additional fields, and those changes are reflected by type inference.

Follow-up: How would you obtain the resulting shape? Use the relevant $Infer type exposed by the server or client, rather than recreating the base User type manually.

QWhere does the User object appear in a session?

A session contains both a session object and a user object. The user property is the User-shaped value for the authenticated account.

Follow-up: Why is this useful? Code handling authentication can access identity data and session metadata through their distinct inferred properties.

QHow can the User type be extended safely?

Plugins and additional user fields can extend the base User type. Better Auth’s TypeScript inference makes those additions available on both the server and client.

Follow-up: What should be checked when a custom field is missing from types? Verify that it was declared using the documented additional-fields configuration and that the generated inference is being used.

  • Session
  • $Infer
  • additionalFields
  • user
  • session

Source: TypeScript. Checked 2026-10-15.