Custom field name or rename field in model for NextAuth.js (Prisma adapter)
Hey!
I'm not a fan of fields named
id
, but rather like to have speaking names like userId
or postId
, which makes the code easier to read imo.
I'm using the Prisma adapter and added all needed models to my schema. In the User
model, I would like to use a field name userId
instead of id
. Is this possible?9 Replies
are you looking to just change the name in the database (keeping
id
itself when you get an object) or to change it in both places?I don't really care how the field is named in the DB, I just want a different name in my code (via TypeScript). I guess having the same name in the model (TS) and the DB is better for consistency, but I have no strong opinion on that.
https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-prisma/src/index.ts
the problem is they have
id
hardcoded in the adapter
if you wanted this, you'd need to copy this file and modify it, then manually keep it up to date
for completeness, note that it is standard for id
to be the identifier of a row, and somethingId
be a foreign key, but it's not a forced thing in generaloh, not gonna happen, way to brittle for my taste 😂
thanks for your input
okay, good to know. Still, having a speaking id is more important to me
gonna create a feature request at NextAuth.js
check if it exists first
did this before posting here, haven't found anything
ok
@Samathingamajig Maybe this can be done with Prisma's
@map
functionality? Something like:
ah I guess the code in NextAuth.js' Prisma adapter is still not aware of the different field name....
i was refering to
@map
when i said
just change the name in the database (keeping id itself when you get an object)