Allow for session
to be associated with the specific account
that was used
#13160
kyle-at-stacks
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
account
was used to create a particularsession
database
session strategyNon-Goals
No response
Background
My team currently has an AuthJS setup with the following characteristics:
database
session strategy in order to have full control over user logins / sessions, implemented with Postgres and RedisaccountLinking
since our user login flow can typically involve multiple different authentication methodsGoogle
,Microsoft
, and nowBoxyHQSaml
to enable SSOWe are moving towards a multi-tenant SSO setup, which will mean that each
company
(internally) will have a specific SSO connection associated with it.When a user signs in, we want to be able to know: "is the account that the user has signed in with from the same SSO connection that is configured for a company"?
This is needed in order to restrict access to a certain
company
based on the current login method, and vice versa.The simplest extension to enable this with AuthJS would be to be able to know which
account
was used for a given session, so we can pass theaccountId
into our backend functions to determine whichcompany
a user has access to (or for any other reason).This situation is of course unique to
database
sessions
which allow for account linking, since we can't simply store which account is used on the user (due to multiple possible sessions).I was not able to identify another way to make this work nicely given the existing setup, other than saving the
accountId
in a cookie, and setting it in thesession
callback.Proposal
Allow an option in the NextAuth config (or enable by default) the
createSession
to accept theaccountId
in it's constructor. It is known at the time of thecreateSession
(according to thehandleLoginOrRegister
function), and is not sensitive.Alternative suggestions or solutions gladly appreciated. I would be willing to contribute if needed.
Beta Was this translation helpful? Give feedback.
All reactions