Account linking with next-auth (Next.js)

Hello Auth0 Community,

I’m currently working on a project using Next.js and next-auth for authentication. Auth0 is the only provider in next-auth configuration.

I’m trying to link user accounts so that a user can sign in with multiple social connections (e.g. Google, Facebook, etc.) using the same or different email address.

The current flow is, when the user is authenticated with Google, there will a be “Link with Facebook” button for them to initiate the account linking process.
Once the user clicked the button, I called

import { signIn } from 'next-auth/react';
signIn('auth0', null ,{ connection: 'facebook' });

However, after successful login with Facebook, next-auth treats user logged in with FaceBook and I can only retrieve account info of Facebook, which is not enough for me to call /api/v2/users/{id}/identities endpoints.

Does anyone have experience using Next-Auth for account linking? Could you point me to any resources or examples that might be helpful? Or perhaps provide some guidance on how to set it up?

Thank you in advance for any help.

I have the same use-case. Are you had success and can share some code? Thanks!

1 Like

You need to use more than one session at the same time. Stored in different cookies. The main reason nextauth doesn’t fully support this is the react components which have a global _NEXTAUTH object.

I modified the library and made a demo deployment showing how it can be done. Demo just uses credentials log in but you can configure for facebook, auth0 etc as well.

https://next-auth-nextjs-git-multi-sessions-demo-gilesbs-projects.vercel.app/