thebergamo / react-native-fbsdk-next

MIT License
693 stars 167 forks source link

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

Open xerdnu opened 2 months ago

xerdnu commented 2 months 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 2 months ago

I also got the same issue :((

stale[bot] commented 4 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

xerdnu commented 3 weeks ago

I found this inside FBLoginManager.ts so it seems that only browser is supported on iOS :(

export type LoginBehaviorAndroid =
  // Attempt login in using the Facebook App, and if that does not work fall back to web dialog auth.
  | 'native_with_fallback'
  // Only attempt to login using the Facebook App.
  | 'native_only'
  // Only the web dialog auth should be used.
  | 'web_only';
/**
 * Indicate how Facebook Login should be attempted on iOS.
 */
export type LoginBehaviorIOS =
  // Attempts log in through the Safari browser.
  // This is the only behavior supported by the native sdk.
  'browser';