BA
Better Auth•2mo ago
0xJJW

BetterAuthOptions database.casing?

Could someone please advise on what the casing option in BetterAuthOptions does? It is referenced in the docs here: https://www.better-auth.com/docs/reference/options#database The code states it's for "table names", but I couldn't get it to work and couldn't find any other references in the repo. https://github.com/better-auth/better-auth/blob/fb303855eecd6e7b1b3131ef7885b8f13e85ada8/packages/better-auth/src/types/options.ts#L95 Many thanks
GitHub
better-auth/packages/better-auth/src/types/options.ts at fb303855ee...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Options | Better Auth
Better Auth configuration options reference.
9 Replies
Ping
Ping•2mo ago
It's casing (not to be confused with casting), it's used during schema generation/migration by the Better-auth CLI to determine the table name's casing (wether camel case or snake case). Though I don't know if that actually works right now, it's kind of just a useless option right now
0xJJW
0xJJWOP•2mo ago
Sorry about the typo, it was very late. I was referring to casing 😅 Thank you for the confirmation, I was going mad trying to reverse engineer what it does. On a side note we achieved mapping via the schema prop on the tables/plugins. I was wondering if you could advise the best approach to making the input and output data for the API snake_case too? The only approach I could see would be too use hooks but I thought I would ask.
Ping
Ping•2mo ago
input and output data for the API snake_case? For example something like the email data during sign up?
0xJJW
0xJJWOP•2mo ago
Yes like email_verified & created_at instead of emailVerified & createdAt. In summary our customers are non technical users so we are opting for a stripe style API that is user friendly. We spin up a db instance for each of our customers.
Ping
Ping•2mo ago
Oh you mean changing the field names, not the data. In that case it depends on which plugins you use. The default field names that are part of Better-Auth can be configured in the auth config: https://better-auth.vercel.app/docs/concepts/database#custom-table-names
Database | Better Auth
Learn how to use a database with Better Auth.
Ping
Ping•2mo ago
Once you change this, make sure your schema matches it for whatever DB you use, then everything should be good to go
0xJJW
0xJJWOP•2mo ago
I must be missing something. We have already configured all of the field names to use snake case and ithe db looks great now. The problem is the API responses are camcelCase and we would ideally like to make them snake_case.
Ping
Ping•2mo ago
Ohh gotcha, yeah I see what you mean now. In most cases you can't really configure the API responses unfortunately. I assume you're talking about the signup or signIn endpoints?
0xJJW
0xJJWOP•2mo ago
Ah ok, yes we would like all data (in and out) to be snake_case. I will see if we can use hooks. We use Kysely and have zod models for the db (snake case) and better auth objects (camel case) so we might be able to do something. Feels hacky though. Thank you for your time.

Did you find this page helpful?