Search code examples
node.jsoauth-2.0passport.jspassport-facebookpassport-google-oauth

Using nodejs passport for multiple OAuth2.0 methods to login to the same account


Im trying to use passport to use OAuth2 to login but I'm not fully understanding the documentation.

My end goal is to have the front page of my website to have multiple login options via twitch/google/facebook that all lead you to the same account if you email happens to match. (example service that does this: streamlabs login) I want to do this without using a username and password so each of my DB docs only have a unique ID to identify each account and subsequent objects keys as twitch/google/facebook containing API tokens and emails.

The part I dont understand is how to tell passport to identify the same DB doc when the user is logged in, from what I think it could be is the callback for the passport strategy registration where you use done(null, profile) to tell passport they have been successfully authed.

Would I have to change profile to the unique DB doc ID to make it universal accross all auth methods?


Solution

  • Turns out I was right, was hoping for an answer earlier before I had to change a bunch of my code