Error: An error occurred while trying to log in to Facebook expo-facebook android issue

Viewed 416

I am trying to implement Facebook login in a simple expo app but on the android expo client, it is not working. Following version, I am using.

"expo-facebook": "~12.0.3",

Method code

const handleAuth = async () => {
  try {
   let options = null;
   if (Platform.OS === "android") {
    options = {appId: "xxxxxxxxxxxxxx"};
   } else {
    options = {
     appId: "xxxxxxxxxxxxxx",
     version: "v9.0",
     appName: "xxxxxxxx",
    };
   }
   let res = await Facebook.initializeAsync(options);
   console.log("[init res]", res);
   const {type, token, expirationDate, permissions, declinedPermissions} =
    await Facebook.logInWithReadPermissionsAsync({
     permissions: ["public_profile"],
    });
   console.log("[type]", type);
   console.log("[token]", token);
   if (type === "success") {
    // SENDING THE TOKEN TO FIREBASE TO HANDLE AUTH
    const credential = app.auth.FacebookAuthProvider.credential(token);
    app
     .auth()
     .signInWithCredential(credential)
     .then((user) => {
      // All the details about user are in here returned from firebase
      console.log("Logged in successfully", user);
      dispatch(saveUser(user));
      navigation.replace("App");
     })
     .catch((error) => {
      console.log("Error occurred ", error);
     });
   } else {
    // type === 'cancel'
   }
  } catch (res) {
   console.log("[res]", res);
   // alert(`Facebook Login Error: ${res}`);
  }
 };

Another error i am facing is FacebookAuthProvider is not available in firebase

firebase": "8.10.0"

I have tried the following ways.

app.auth.FacebookAuthProvider

Or

app.auth().FacebookAuthProvider

but both are not working.

Please help if anyone integrated facbook login in. "expo": "~44.0.0"

0 Answers
Related