Cloudflare + React Router v7 and Better Auth
It seems there is no clear answer on how to actually use Better Auth with Cloudflare D1. As a beginner, I have searched high and low for what is seemingly an impossible answer.
From the Better Auth documentation I am able to only get to step 3 (https://www.better-auth.com/docs/installation)
- The problem starts with Better Auth: Better Auth does not support Cloudflare D1 out of the box
- Third-party packages are required: Both Kysely and Kysely-D1 are needed to do something with Better Auth and unfortunatly the documentation is non-existent as to how Kysley talks to Cloudflare D1 and Better Auth or why these third-party packages are required
- Lack of a clear way forward: I have found several resources and claim "Better Auth + Cloudflare D1, just add water" however when reviewing the project setups every Better Auth and Kysely conguration is different
From the Better Auth documentation I am able to only get to step 3 (https://www.better-auth.com/docs/installation)
- npm install better-auth
- created .dev.vars in project root; add the variables (generate secret key, url is http://localhost:5173)
- created auth.ts in app/utils
- Further reading leads me to the other supported databases pages, https://www.better-auth.com/docs/adapters/other-relational-databases
- "Better Auth supports a wide range of database dialects out of the box thanks to Kysely." - but as a beginner, I have no idea what this actually means
- Under *Kysely Community dialects* I see "Cloudflare D1", https://github.com/aidenwallis/kysely-d1
- https://github.com/aidenwallis/kysely-d1 has only 1 instruction, "npm i kysely-d1" but no other context for where to put that code that's in the readme.md file. Replace auth.ts?
GitHub
D1 dialect for Kysely. Contribute to aidenwallis/kysely-d1 development by creating an account on GitHub.