How to authenticate with multiple databases #10790
Unanswered
discoverlance-com
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
-
I am working on an application that works with several databases. Each user account that has access to the application lives in it's organisation's database.
When using the database adapter with authjs, in this case, drizzle ORM for instance, I can only supply a single DB connection/tables which means auth js will look for the database or tables from that single DB client passed into the drizzle provider. But this is not the case as my database is different for each organisation's users as they have different connections to different databases.
I run into a couple of issues:
How do I pass the database dynamically? For instance, after making a manual check to determine the organisation and that email belongs to, how can I then pass that organisation's database as what should be used for the login to Next Auth or should be used by Next Auth for authenticating the account.
How do I ensure that on session token checks or even refresh by Next Auth, I can pass the right database for the check? This might even mean that I should disable auth verifications or refresh but with database authentication, there's a need to make a connection to the database to verify the session token. So I will need to pass the database that should be used each time. In this case, an alternative is to disable the database authentication and use jwt only which should not consult the server or database for token verifications or refresh.
Beta Was this translation helpful? Give feedback.
All reactions