Session-aware application code
Reading the authenticated identity from a session response.
Better Auth · Type Alias
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.
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.
type User = /* inferred Better Auth user object */The inferred authenticated user object shape, including fields contributed by plugins and configured additional fields.
user from session metadata under session.$Infer to obtain the User shape generated by the configured authentication system.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.
Reading the authenticated identity from a session response.
Sharing user properties between frontend and backend without manually duplicating interfaces.
Adding plugin or application-specific user properties while retaining inference.
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.
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.
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$InferadditionalFieldsusersession