Skip to content

'sv add better-auth' generates wrong import: better-auth/minimal does not export User / Session #1099

@Nyasper

Description

@Nyasper

Describe the bug

Running npx sv add better-auth generates src/app.d.ts with:

import type { User, Session } from 'better-auth/minimal';

However, better-auth/minimal only exports BetterAuthOptions and betterAuth. It does not export User or Session.

The correct import should be from the main package:

import type { User, Session } from 'better-auth';

Impact

With skipLibCheck: true (SvelteKit default), the failed import is silently swallowed and both User and Session fall back to any. This means event.locals.user and event.locals.session are typed as any throughout the entire application — a critical type-safety hole.

With skipLibCheck: false, the actual error surfaces:

Module '"better-auth/minimal"' has no exported member 'Session'.

Reproduction

  1. Create a fresh SvelteKit project with npx sv create
  2. Run npx sv add better-auth
  3. Check the generated src/app.d.ts
  4. The import path is better-auth/minimal but that module doesn't export User/Session

Fix

In packages/sv/src/addons/better-auth.ts, change the import line from:

- import type { User, Session } from 'better-auth/minimal';
+ import type { User, Session } from 'better-auth';

Additional context

  • This may be related to migrate better-auth to 1.6 #969 (better-auth 1.6 migration). Newer versions of better-auth may have changed the internal module structure.
  • The better-auth/minimal submodule (checked at better-auth@1.4.21) only exports BetterAuthOptions and betterAuthUser and Session are only available from the main entry point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions