thebergamo / react-native-fbsdk-next

MIT License
667 stars 166 forks source link

Login always opens WebView instead of native app on iOS #556

Open xerdnu opened 6 days ago

xerdnu commented 6 days ago

Im having an issue where the login doesnt work as expected on ios. The facebook login always defaults to opening a webview instead of using the native facebook app.

I noticed in the source code that LoginManager.setLoginBehavior has return for ios so i guess this is intentionally disabled on ios?

Minimal code to reproduce the behavior

const onFacebookButtonPress = async () => {

  console.log("Begin sign in: Facebook");

  // Not supported on ios?
  LoginManager.setLoginBehavior('NATIVE_WITH_FALLBACK');

  // Attempt login with permissions
  const result = await LoginManager.logInWithPermissions(['public_profile', 'email']);

  if (result.isCancelled) {
    console.log('User cancelled the login process');
    return;
  }

  // Once signed in, get the users AccesToken
  const data = await AccessToken.getCurrentAccessToken();

  if (!data) {
    throw 'Something went wrong obtaining access token';
  }

  // Create a Firebase credential with the AccessToken
  const facebookCredential = auth.FacebookAuthProvider.credential(data.accessToken);

  // Sign-in the user with the credential
  return auth().signInWithCredential(facebookCredential).catch(function(error) {
      if (error.code === "auth/account-exists-with-different-credential"){
          alert("Facebook account does not exist.");
      } else {
          alert(error.message);
      }
      console.log(error.message+" with code: "+error.code);
  });
}

I would be really grateful if anyone could provide some clarification if the native login i supported on ios and if there are any workaround to make the native app open instead of the webview.

Best regards!

solitarysp commented 3 days ago

I also got the same issue :((