This library is in early development. Expect breaking changes.
Core Concepts

Auto‑Imports and Aliases

What the module registers for you.

Auto‑imports

Client

  • useUserSession()

Server

  • serverAuth()
  • getUserSession(event)
  • requireUserSession(event, options?)

Components

  • <BetterAuthState>

Usage Examples

Server Utils (auto-imported in server/)

server/api/profile.ts
export default defineEventHandler(async (event) => {
  // These are auto-imported, no import statement needed
  const session = await getUserSession(event)
  const auth = serverAuth()
})

Client Composables (auto-imported in Vue components)

pages/dashboard.vue
<script setup>
// Auto-imported, no import statement needed
const { user, loggedIn } = useUserSession()
</script>

Aliases

AliasResolves to
#nuxt-better-authModule types (AuthUser, AuthSession)