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
accountwas used to create a particularsessiondatabasesession strategyNon-Goals
No response
Background
My team currently has an AuthJS setup with the following characteristics:
databasesession strategy in order to have full control over user logins / sessions, implemented with Postgres and RedisaccountLinkingsince our user login flow can typically involve multiple different authentication methodsGoogle,Microsoft, and nowBoxyHQSamlto 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
companybased on the current login method, and vice versa.The simplest extension to enable this with AuthJS would be to be able to know which
accountwas used for a given session, so we can pass theaccountIdinto our backend functions to determine whichcompanya user has access to (or for any other reason).This situation is of course unique to
databasesessionswhich 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
accountIdin a cookie, and setting it in thesessioncallback.Proposal
Allow an option in the NextAuth config (or enable by default) the
createSessionto accept theaccountIdin it's constructor. It is known at the time of thecreateSession(according to thehandleLoginOrRegisterfunction), 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