Docs

Typescript

Better Auth is designed to be type-safe. Both the client and server are built with TypeScript, allowing you to easily infer types.

Infering Types

Both the client SDK and the server offer types that can be inferred using the $Infer property. Plugins can extend base types like User and Session, and you can use $Infer to infer these types. Additionally, plugins can provide extra types that can also be inferred through $Infer.

client.ts
import {  } from "better-auth/client"
 
const  = ()
 
export type  = typeof ..

The Session type includes both session and user properties. The user property represents the user object type, and the session property represents the session object type.

You can also infer types on the server side.

auth.ts
import {  } from "better-auth"
 
export const  = await ({
    : {
        : "sqlite",
        : "./db.sqlite",
    }
})
 
type  = typeof ..

On this page

Edit on GitHub