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
Please try to add this line to the top.
Did you import Alert from react-native?
first,
You’re good to go!
You should add this
import *
as Facebook from ‘expo-facebook’;Alert.alert is throwing this error. Replace it with “console.log” or simple alert.