How to fix standalone android Expo Facebook login

Hi everyone,

I got Facebook auth working on my standalone iOS and Android app in production. I ran into a few problems when trying to get Facebook working for android and narrowed it down to this one problem.

If the Facebook app is installed on your android device and you try to continue with only

const { type, token } = await Expo.Facebook.logInWithReadPermissionsAsync(appId, {
permissions: [‘public_profile’, ‘email’],
});

it will fail because it tries to open the native Facebook app and you will get Login error: There is an error in logging you into this application. Please try again later. "

I tried multiple different things, but what helped me realize the problem was when I removed the Facebook app from my android device - the WebView popped up when trying to login with Facebook.

So, as a fix to the problem add “behavior: web” if you are using Facebook Expo auth on a standalone Android app OR check the platform so it’s compatible with both platforms like this:

const { type, token } = await Expo.Facebook.logInWithReadPermissionsAsync(appId, {
permissions: [‘public_profile’, ‘email’],
behavior: Platform.OS === ‘android’ ? ‘web’ : ‘system’,
});

This almost drove me nuts - so I wanted to share it online with anyone else that might be facing this problem in a standalone Android app on the Google PlayStore.

Cheers

3 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.