Simultaneous Sessions with Different Providers #1728
Replies: 6 comments 9 replies
-
signIn is totally possible, check the docs for custom providers ;) https://next-auth.js.org/getting-started/client#starts-google-oauth-sign-in-flow-when-clicked signOut and useSession are app level though, not provider level. depending on if you want to use a DB or simple jwt sessions, check the docs again https://next-auth.js.org/configuration/callbacks https://next-auth.js.org/configuration/providers#using-a-custom-provider id will be the thing you pass to signIn |
Beta Was this translation helpful? Give feedback.
-
I'm interested in it too |
Beta Was this translation helpful? Give feedback.
-
We're in a similar scenario where we need to support two simultaneous sessions (one is considered "admin", the other is considered "impersonation"). The admin session is a refresh token grant, and the impersonation session is OAuth (+OIDC). We're currently exploring serving NextAuth via two separate API paths, one under Not seeing any way of configuring If anyone else has successfully rolled simultaneous sessions via NextAuth, would love to hear how. |
Beta Was this translation helpful? Give feedback.
-
For posterity: We did not find a solution to this problem and ended up redesigning our backend systems to work around this missing functionality. |
Beta Was this translation helpful? Give feedback.
-
An update here: We found a solution that uses NextAuth v4's new 'advanced initialization' strategy (docs here), where we're essentially maintaining a copy of the second session in a cookie. We're still using the NextAuth This is working well enough for us but obviously not ideal. I wouldn't recommend NextAuth takes this on as a first-class pattern since maintaining multiple sessions simultaneously is an anti-pattern. A low-impact update that would've made this simultaneous session management achievable without |
Beta Was this translation helpful? Give feedback.
-
This demonstrates using multiple sessions. I got rid of __NEXTAUTH, made SessionProvider pointable to each session and added a SessionsProvider which puts all the sessions into the context and a useSessions hook. https://next-auth-nextjs-git-multi-sessions-demo-gilesbs-projects.vercel.app/ |
Beta Was this translation helpful? Give feedback.
-
I have two separate backends which my frontend needs to send requests to. However, they use different OAuth2 providers, one of which is not under my control. I need to have the user auth into each system separately and then maintain two separate sessions simultaneously so that I can marshal requests to each of the two backends with its respective session.
Is this feasible in next-auth? In my dream world, I'd have some syntax like
signIn('backend1')
,signOut('backend1')
,useSession('backend1')
, etc., to allow me to specify to next-auth which session to use.Beta Was this translation helpful? Give feedback.
All reactions