Using a user ID from application code (may be Postgres specific) #10876
Unanswered
spencerwilson
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
When using adapter-pg, the database stores a user's ID as an integer: https://github.com/nextauthjs/next-auth/blob/%40auth/pg-adapter%400.7.2/packages/adapter-pg/schema.sql#L42
This seems at odds AdapterUser.id, which says that id is a string: https://authjs.dev/reference/core/adapters#adapteruser
This inconsistency makes it difficult to use user IDs in TypeScript. Other data models use
id: number
, matching what's in the users table; when comparisons to an AdapterUser.id (such as session.user?.id, when doing this trick; this is useful for authorization policy evaluation) the compiler reports a type mismatch between the user ID stored in the database and that on the session.My current workaround is to obtain the user ID via
Number(session.user!.id!)
and compare that to db-stored user ID values.Am I missing something? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions