#better auth generate error

4 messages · Page 1 of 1 (latest)

minor trout
#

[#better-auth]: Couldn't read your auth config in /home/ricardo/Documents/marketpleace/packages/backend/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.

earnest graniteBOT
#

Hi @minor trout. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The error message:

Couldn't read your auth config in /home/ricardo/Documents/marketpleace/packages/backend/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.

indicates that the Better Auth CLI is unable to find a properly exported auth instance in your auth.ts file. According to the local install instructions for Better Auth, you need to ensure that your convex/betterAuth/auth.ts file exports a static auth instance, either as a default export or as a named export called auth.

Here’s the correct way to do it:

import { createAuth } from '../auth'
import { getStaticAuth } from '@convex-dev/better-auth'

// Export a static instance for Better Auth schema generation
export const auth = getStaticAuth(createAuth)

Make sure that:

  • The file is located at the correct path (e.g., convex/betterAuth/auth.ts).
  • You are exporting auth as shown above (not as a default export, but as a named export called auth).
  • The CLI is being run from the correct directory, and the path to your auth.ts matches what the CLI expects.

If you follow this pattern and the error persists, double-check the file path and export syntax. The CLI specifically looks for a named export auth or a default export of the auth instance in the specified file, as described in the local install guide.

If your file is named or structured differently, or if you are not exporting auth correctly, the CLI will not be able to read your config and will throw this error.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@minor trout Kapa.ai is still learning and improving, please let me know how I did by reacting below.