How do I link next-auth user with database user when using facebook provider?
Hey, I'm setting up a new app with next-auth for the first time. On facebook provider subpage it says that facebook not always returns an email due to the fact that sometimes users set up their account with mobile only. That's fine with me, but I do not see a way to link the user with his documents in database. I thought the flow should go like this:
user without an account signs in with FB -> if he has an email, then I check for it in db -> he does not have an account, I create new record in DB - user is linked by email.
user without an account signs in with FB -> if he does NOT have an email, then I check his facebook account's id -> he does not have an account, I create new record in DB - user is linked by id.
However, each time I login with facebook both token.sub
and user.id
are different than previously, so I don't see a way I could link his data with user inside database. What am I missing?