I'm building a simple React Native app which implements "Login with Facebook" using react-native-fbsdk
I can login and logout as the button changes from Log in to Log out when logging with credentials, but the onLoginFinished
callback never gets fired, though onLogoutFinished
works properly.
Here is my code:
import React, { Component } from 'react';
import { View,Alert,Button,Text } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
userInfo: null
}
}
onFacebookLoginFinished = (error, result) => {
if (error) {
Alert.alert("login has error: " + result.error);
} else if (result.isCancelled) {
Alert.alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
Alert.alert(data.accessToken.toString())
this.props.navigation.navigate('Home')
}
)
}
}
render() {
return (
<View>
<LoginButton
onLoginFinished={this.onFacebookLoginFinished}
onLogoutFinished={() => Alert.alert("logout.")}/>
</View>
);
}
};
I think you should try this.
onLoginFinished={(error, result) => this.onFacebookLoginFinished(error, result)}
Change the function into this.
onFacebookLoginFinished (error, result){
...
}