Types
Use this page when you need the public TypeScript surface exposed by the module and its generated auth types.
import type {
AppSession,
AuthActionError,
AuthMeta,
AuthMode,
AuthRouteRules,
AuthSocialProviderId,
AuthSession,
ClientAuthSession,
AuthUser,
RequireSessionOptions,
UserMatch,
} from '@nuxtjs/better-auth'
AuthUser
The user object returned by useUserSession().
Additional fields depend on your Better Auth plugins.
AuthSession
The full session returned by server helpers, including its token.
ClientAuthSession
The session object returned by useUserSession(). This is Omit<AuthSession, 'token'> and preserves additional session fields inferred from your configuration.
AuthMeta
Used in page meta and route-rule auth entries (routeRules.auth or nitro.routeRules.auth).
definePageMeta({ auth: 'user' satisfies AuthMeta })
definePageMeta({ auth: { only: 'guest', redirectTo: '/' } satisfies AuthMeta })
AuthRouteRules
Extends Nitro route rules with:
auth?: AuthMeta
export default defineNuxtConfig({
routeRules: {
'/dashboard': { auth: 'user' } satisfies AuthRouteRules,
},
})
export default defineNuxtConfig({
nitro: {
routeRules: {
'/dashboard': { auth: 'user' } satisfies AuthRouteRules,
},
},
})
UserMatch<T>
Used for user matching in AuthMeta.user and RequireSessionOptions.user (OR logic for arrays, AND logic between fields).
RequireSessionOptions
The options object for requireUserSession(event, options?).
It is augmentation-aware: user matching and rule callback context use AuthUser / AuthSession from #nuxt-better-auth.
signOut options
Used by signOut(options?) to run a post-sign-out callback:
await signOut({ onSuccess: () => navigateTo('/') })
AuthSocialProviderId
Typed provider ids inferred from your configured socialProviders.
import type { AuthSocialProviderId } from '@nuxtjs/better-auth'
const provider: AuthSocialProviderId = 'github'
This replaces verbose extraction patterns like:
type SocialProvider = Parameters<NonNullable<AppAuthClient>['signIn']['social']>[0]['provider']
Module augmentation
Augment AuthUser / AuthSession by declaring module #nuxt-better-auth.
Using Types
In Vue Components
<script setup lang="ts">
import type { AuthUser } from '#nuxt-better-auth'
const props = defineProps<{
user: AuthUser
}>()
</script>
In Server Code
import type { AuthUser, AuthSession } from '#nuxt-better-auth'
export default defineEventHandler(async (event): Promise<AuthUser> => {
const { user } = await requireUserSession(event)
return user
})