new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Better Auth · Concepts · all subjects

typescript

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Better Auth requires TypeScript strict mode

Better Auth is designed to work with TypeScript's strict mode. The strict compiler option should be enabled in tsconfig.json for proper type inference. If strict mode cannot be enabled, at minimum strictNullChecks must be set to true. When strict is true, strictNullChecks is automatically enabled. If strictNullChecks is explicitly set to false, type inference issues will occur.

Infer Session type from auth client

The Session type can be inferred from the auth client using the $Infer property. The syntax is: export type Session = typeof authClient.$Infer.Session. The Session type includes both session and user properties, where the user property represents the user object type and the session property represents the session object type.

Infer Session type from server auth

The Session type can be inferred from the server-side betterAuth instance using the $Infer property. The syntax is: type Session = typeof auth.$Infer.Session. This works on the server side to get fully typed session and user information.

Add additional fields to user object

Additional fields can be added to the user object through the additionalFields configuration in the betterAuth config. Each field requires a type property. Example: additionalFields: { role: { type: "string", input: false } }. These additional fields are automatically inferred in the Session type on both client and server.

The input property controls user field mutability

The input property in an additional field configuration determines whether a field should be included in user input during operations like registration. It defaults to true, meaning the field is part of user input by default. Set input: false to prevent users from setting the field, which is important for security-sensitive fields like role.

Infer additional fields in monorepo client setup

For monorepo or single-project setups where server and client code are in the same project, use the inferAdditionalFields plugin to automatically infer additional fields from the server configuration. The pattern is: createAuthClient({ plugins: [inferAdditionalFields<typeof auth>()] }) where auth is imported as a type from the server.

Manually specify additional fields in separate client project

For separate client-server projects, manually specify additional fields when creating the auth client using the inferAdditionalFields plugin. Pass the field definitions directly: createAuthClient({ plugins: [inferAdditionalFields({ user: { role: { type: "string" } } })] }).

Disable declaration and composite in tsconfig for large type inference

If TypeScript inference exceeds the maximum length the compiler will serialize, ensure that both declaration and composite are not enabled in tsconfig.json, in addition to following strict mode recommendations.

Give your agent this brain