How can I make the user ID an auto-incrementing integer?

I have already seen the github issue related to this topic, but no information on how to actually do this and still get type safety is explained. I have already disabled generating ids in my config, but how can I get it to show up as a number and not a string? Here's my config (using nextjs):
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "pg" }),
emailAndPassword: {
enabled: true,
},
plugins: [nextCookies()],
advanced: {
generateId: false,
},
});
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "pg" }),
emailAndPassword: {
enabled: true,
},
plugins: [nextCookies()],
advanced: {
generateId: false,
},
});
7 Replies
Marcus
MarcusOP4mo ago
Update: i ended up doing this at the moment, works for passing the User as props to a function, but the main functions aren't typed correctley still
type DefaultUser = typeof auth.$Infer.Session.user;
export interface User extends Omit<DefaultUser, "id"> {
id: number;
}
type DefaultUser = typeof auth.$Infer.Session.user;
export interface User extends Omit<DefaultUser, "id"> {
id: number;
}
bekacru
bekacru4mo ago
feel free to open an issue on gh
Marcus
MarcusOP2mo ago
Ok i will thank you Still having this issue, no solution on github
Marcus
MarcusOP2mo ago
GitHub
How can I make the user ID an auto-incrementing integer? · Issue #9...
Is this suited for github? Yes, this is suited for github To Reproduce Create a new nextjs app (create-next-app) Install drizzle-orm Install and setup better-auth using email & password, but ch...
bekacru
bekacru2mo ago
what are the issues? make sure to set advanced.generateId to false and you should be good in general.
Marcus
MarcusOP2mo ago
the id returned by the auth client in functions like getSession are still typed as string even though its an serial in the database hello? is there any update on this?
bekacru
bekacru2mo ago
not yet. but you can override the type manually, no? the problem is this requires a config on the client and on the auth server and we can't just add a random API to do it, it needs to be purposeful. We just haven't figured out the right API yet.

Did you find this page helpful?