Search code examples
ruby-on-railsfacebookuid

Facebook UID from response doesn't match with user's uid stored in database


I have a problem on production with Facebook login which happened today. I'm using Rails omniouth-facebook gem for authentication users via Fb.

So, after some debugging I figure out that uid which I got in response from Facebook isn't the same as uid which particular user has stored in database.

I have this part:

find_by(provider: auth.provider, uid: auth.uid)

where auth is env['omniauth.auth'] and when I manually check user with auth.email in my database uids not matched, so this function always returns nil and Login Failure.

Does anybody has idea what could be the problem? Really would appreciate any hint.

Thanks, Bojan


Solution

  • With API v2.0, Facebook introduced app-scoped user ids.

    For every new user that logs in to your app after the switch was made to 2.0, you will not get their “global” user id any more, but only an app-scoped one, that is unique to your app - to be more specific, it is tied to your app id.

    So if you are using different app ids, resp. switched app ids at some point, of course you will get different app-scoped ids for the same user.

    If you have a business that has several apps, you can connect them via Business Manager, so that you can connect the different app-scoped user ids for different apps.