I have encountered an issue where, after logging in with Google, I need to obtain access tokens for Twitter and LinkedIn in order to make API requests for posting. However, when using NextAuth, it changes my session to either Twitter or LinkedIn, whereas I need to keep my session data from the Google sign-in. How can I resolve this problem?
To resolve this issue, I may need to modify the implementation of NextAuth to handle multiple authentication providers without affecting the existing session data. Alternatively, I could explore different authentication strategies or libraries that support multiple providers while maintaining the desired session behavior.
Use multiple sessions, each with a separate cookie.
Next.js supports this server side. You can just have multiple authentications configured with cookie names. However, their React components will not display multiple sessions, because they use a global __NEXTAUTH object to store the configuration. This means I had to modify the library a bit to make it work.