Skip to content

typed nitro route inference for /api/auth endpoints #194

@onmax

Description

@onmax

Describe the bug

When using @onmax/nuxt-better-auth in a Nuxt 4 app, Nitro route typing for auth endpoints is too generic, so client-side useFetch('/api/auth/customer/state') cannot infer a useful response shape.

Current behavior

Generated Nitro route types contain only a wildcard route:

'/api/auth/**': {
  default: ...ReturnType<typeof import('.../api/auth/[...all]').default>
}

And the catch-all handler type resolves to:

declare const _default: EventHandler<EventHandlerRequest, Promise<Response>>

This makes endpoint-specific inference effectively unavailable for /api/auth/* consumers.

Expected behavior

At least one of the following:

  1. Expose endpoint-level typing for known auth routes (e.g. /api/auth/customer/state) so useFetch can infer return types.
  2. Export public TS types for key route payloads (customer state, session state, etc.) so consumers can type local wrappers without guessing.
  3. Provide a documented helper/composable that returns typed data for these common auth endpoints.

Reproduction

  1. Create a Nuxt 4.3.x app with @onmax/nuxt-better-auth.
  2. Run nuxi prepare.
  3. Inspect .nuxt/types/nitro-routes.d.ts and note '/api/auth/**' wildcard.
  4. Use useFetch('/api/auth/customer/state') in app code.
  5. Observe that payload shape is not inferred (manual typing is required).

Environment

  • Nuxt: 4.3.1
  • Nitro: 2.13.1
  • @onmax/nuxt-better-auth: 0.0.2-alpha.29

Additional context

This mainly impacts DX and maintainability in app-level composables that consume auth/customer endpoints.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions