Can't use @better-auth/cli when exporting a auth function
I am using Better Auth across my api (hono + cloudflare workers) and fronted (nextjs + vercel), so far so good however when i want to run the
bunx @better-auth/cli generate
bunx @better-auth/cli generate
i get the following error:
$ bunx @better-auth/cli generate --config ../api/src/common/auth.ts --output ./src/schemas/auth.tsERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in BuzzTrip/packages/api/src/common/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.error: script "db:auth" exited with code 1
$ bunx @better-auth/cli generate --config ../api/src/common/auth.ts --output ./src/schemas/auth.tsERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in BuzzTrip/packages/api/src/common/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.error: script "db:auth" exited with code 1
Plan the trip you've always dreamed of. Contribute to jacobsamo/BuzzTrip development by creating an account on GitHub.
Solution
you can call
import { getMigrations } from "better-auth/db";const { runMigrations } = await getMigrtions(auth.options);await runMigratinos() //this will run the migrations for you
import { getMigrations } from "better-auth/db";const { runMigrations } = await getMigrtions(auth.options);await runMigratinos() //this will run the migrations for you