Failed to initialize database adapter
I'm currently running the Drizzle adapter, and currently cannot get it to generate a schema.
The following
auth.ts
causes the cli to throw:
Failed to initalize database adapter
The database is currently the following:
When using the following base for betterAuth it successfully tells me:
✔ Your schema is already up to date.
28 Replies
make sure both the cli and the better auth versions are upto date. There was a breaking change.
I see, will check in a bit, it works with just making a pool with it, but not with Drizzle from above at least.
any resolution yet?
could you please check for me if it works for you with sqlite db? use
better-sqlite3
just checked, same issue with sqlite
It's passing all possible tests with Drizzle, that what makes it difficult to track down the problem. Anyway, in case you're using an older version or if there was a version causing the issue, could you try
0.8.6-beta.5
?I’ll check that version in a bit @bekacru
If you saw my other bug report it’s with your adapter
Debugging now, seems to be a issue with the
/src/db/utils.ts
and specifically:
If you allowed us to pass a adapter so basically you made a abstract version of this I could test itthis should only happen if the adapter format isn't updated. Please make sure both the
cli
and the package is on latest.I haven't updated since the first time I reported this bug, I was just forwarding what I put in from #Failed to initialize database adapter.
I'll take a look later to see if it's fixed at all.
Just tried with 0.8.7 beta 1, still not working
Is it only
signIn.email
that doesn't work, or do none of the other APIs work either?None of them work, not even signin with google and signup with email
Nothing works for me either @bekacru and it won't due to the
init.ts
failing in that utils area.I think you have differnt issue
yours is you can't make it generate the schema, right?
No
the entire auth system doesn't work
generate schema is apart of this issue as it gives the same errors
I mentioned this bc based on https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/init.ts the first line you do is
const adapter = await getAdapter(options);
which hooks into our options.GitHub
better-auth/packages/better-auth/src/init.ts at main · better-auth/...
The most comprehensive authentication library for TypeScript - better-auth/better-auth
okay so went to the full rabit hole. Drizzle itself isn't working for me without better auth. I cahnged the db connection to use pool
and it start working again
tried this but not working for me, getting this error:
⨯ TypeError: dialect.createDriver is not a function
at new Kysely (node_modules/.pnpm/[email protected]/node_modules/kysely/dist/esm/kysely.js:74:35)
at Ee (node_modules/.pnpm/[email protected]/node_modules/better-auth/dist/index.js:83:20441)
at jt (node_modules/.pnpm/[email protected]/node_modules/better-auth/dist/index.js:83:24510)
at Mt (node_modules/.pnpm/[email protected]/node_modules/better-auth/dist/index.js:83:25114)
at tc (node_modules/.pnpm/[email protected]/node_modules/better-auth/dist/index.js:83:27422)
at <unknown> (src/lib/auth.ts:21:31)
72 | else {
73 | const dialect = args.dialect;
> 74 | const driver = dialect.createDriver();
| ^
75 | const compiler = dialect.createQueryCompiler();
76 | const adapter = dialect.createAdapter();
77 | const log = new Log(args.log ?? []);
POST /api/auth/sign-in/social?currentURL=https%3A%2F%2Flocalhost%3A3000%2F 500 in 536ms
hmm why is this a kysley error?
I'm stuck on 0.6.2 until I can figure out how to move to the newer version as I run a custom adapter that runs off Drizzzle
are you using drizzle with pg?
Not sure, I am using just drizzle
Exactly this code
no this would never through the above error
check if you're using drizzle adapter in your auth config
also make sure to import
Pool
from pg
Oh, I actually directly called this from auth.ts replacing DrizzleAdapter completely, my bad.
This is something I already had in my db.ts file which I am passing to DrizzleAdapter in auth.ts
i have two projects runing 0.6.2, both with drizzle, one on pg, and one is a custom adapter as you don't support the database type
they both run into that error on the newer versions.
yeah change that
"Failed to initialize database adapter" only means one thing. the adapter wasn't a valid adapter meaning it didn't return a function
which should never happen unless there is a version mismatch or your custom adapter isn't quite correct
for your custom adapter the new adapter interface is
it used to be just
Adapter
in older versionsyeah, just tried this and it works!
I was using your base adapter code from the latest version, it was occuring with the default drizzle stuff too