skip to Main Content

I’m trying to authenticate users using facebook. I’m able to successfully ask for permission and authorize a user on the facebook platform, but then the app returns and error on redirect and produces the following error -> Facebook Login Error: Can't find variable: Alert. Yes I have Alert syntax in my facebook login method, but I simply cannot locate where this error is being triggered.

Has anyone experienced this before?

   facebookSignIn = async () => {
  try {
    const {
      type,
      token,
      expires,
      permissions,
      declinedPermissions,
    } = await Expo.Facebook.logInWithReadPermissionsAsync('<APP ID>', {
      permissions: ['public_profile'],
    });
    if (type === 'success') {
      // Get the user's name using Facebook's Graph API
      const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`);
      Alert.alert('Logged in!', `Hi ${(await response.json()).name}!`);
      this.props.navigation.navigate('SenderHPP');
    } else {
      // type === 'cancel'
    }
  } catch ({ message }) {
    alert(`Facebook Login Error: ${message}`);
  }
};

4

Answers


  1. Please try to add this line to the top.

    import { Alert } from 'react-native';
    
    Login or Signup to reply.
  2. Did you import Alert from react-native?

    first,

    import { Alert } from 'react-native';
    

    You’re good to go!

    Login or Signup to reply.
  3. You should add this

    import *as Facebook from ‘expo-facebook’;

    Login or Signup to reply.
  4. Alert.alert is throwing this error. Replace it with “console.log” or simple alert.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search