I'd like to activate Facebook login by react native firebase. My purpose is to move to Signin screen to Main Screen.
I use,
react-native: 0.52.2 react-native-firebase: ^3.2.4 react-navigation: ^1.0.0-beta.28
LoginScreen.js
const facebookLogin = () => {
return LoginManager
.logInWithReadPermissions(['public_profile', 'email'])
.then((result) => {
if (!result.isCancelled) {
console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`)
// get the access token
return AccessToken.getCurrentAccessToken()
}
})
.then(data => {
if (data) {
// create a new firebase credential with the token
const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken)
// login with credential
return firebase.auth().signInAndRetrieveDataWithCredential(credential)
}
})
.then((currentUser) => {
if (currentUser) {
console.log(currentUser);
return this.props.navigation.navigate('Main');
}
})
.catch((error) => {
console.log(`Login fail with error: ${error}`)
})
}
After (currentUser), I added following that.
this.props.navigation.navigate('Main');
But that doesn't work! I have already set up Router, and that did work at out of Auth Component.
I checked at console.log and that shows me:
Login fail with error: TypeError: Cannot read property 'navigate' of undefined"
So I tried to move const { navigation } = this.props; from Auth Component to other SigninScreen Component. But I can't see successful login.
Thanks for your answer. And I have defined already in Parent component.
I defined navigation here.
class SignInScreen extends React.Component {
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.containerStyle}>
<TouchableOpacity onPress={facebookLogin}>
<Text style={styles.textStyle}>Facebook</Text>
</TouchableOpacity>
</View>
);
}
}