This library is in early development. Expect breaking changes.
Getting Started

Type Augmentation

Learn how the module automatically infers types from your configuration.

When you add Better Auth plugins that extend the user or session objects, TypeScript needs to know about these new fields. The module automatically infers types from your configuration, but you can also augment types manually.

Automatic Type Inference

Types are automatically inferred when you:

  • Add plugins to server/auth.config.ts
  • Use the module's type exports

No additional configuration is needed for most cases.

Example:

If you add the admin plugin:

server/auth.config.ts
import { admin } from 'better-auth/plugins'
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'

export default defineServerAuth({
  plugins: [admin()]
})

You can immediately access the role property in your Vue components:

<script setup lang="ts">
const { user } = useUserSession()

// user.value.role is fully typed!
if (user.value?.role === 'admin') {
  // ...
}
</script>

Manual Type Augmentation

Manually extend types when automatic inference doesn't work:

Create a file types/auth.d.ts:

types/auth.d.ts
import '#nuxt-better-auth'

declare module '#nuxt-better-auth' {
  interface AuthUser {
    customField?: string
  }
}
The #nuxt-better-auth virtual module exports AuthUser and AuthSession interfaces that reflect your current configuration.

Troubleshooting

Types not updating?

  1. Restart your IDE's TypeScript server
  2. Run npx nuxi prepare to regenerate types
  3. Check that your server/auth.config.ts has no syntax errors
Now that you are set up, learn How it Works.