Error with Facebook login: [TypeError: Cannot read property 'initializeAsync' of undefined]

SDK Version: 49.0.0
React Native Version: 0.72.1
Expo-Facebook Version: 12.2.0
Platforms(Android/iOS/web/all): iOS

Here is the code:

import React, { useContext } from "react";
import { View, Button, Text } from "react-native";
import * as Facebook from "expo-facebook";
import { AuthContext } from "../Hooks/userAuthentication";

const LoginScreen = () => {
  const { signIn } = useContext(AuthContext);
  const handleFacebookLogin = async () => {
    try {
      await Facebook.initializeAsync({
        appId: "6439422697501635",
      });

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

      if (type === "success") {
        // Get user details using the access token
        // You can make an API call to your server to authenticate the user
        console.log(token);
        signIn();
      } else {
        // Handle the case when the user cancels or encounters an error
        console.log("Facebook login canceled or encountered an error.");
      }
    } catch (error) {
      console.log("Error with Facebook login:", error);
    }
  };

  return (
    <View>
      <Button title="Login with Facebook" onPress={handleFacebookLogin} />
    </View>
  );
};

export default LoginScreen;

The expo-facebook library is deprecated from SDK 46. Please seek alternative libraries such as react-native-fbsdk-next: GitHub - thebergamo/react-native-fbsdk-next

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