Reputation: 41
**Please Help anyone. I can't log out of Firebase. It continuously giving me an error. Here is my code below. ** I have tried the authentification of the current user, but it still says that the current user object is null, and a user is an object. And also I have called this function in a dashboard class, but if I call this LoginOut component separately it works fine. Maybe the calling component in the dashboard class is the problem, I'm confused, Help me?!!
// database/firebaseDb.js
import * as firebase from 'firebase';
const firebaseConfig = {
apiKey: "AIzaSyADgtLqQHs1KAlnMKUn8uM_vpasRUkWchw",
authDomain: "reactnativefirebase-9ed38.firebaseapp.com",
projectId: "reactnativefirebase-9ed38",
storageBucket: "reactnativefirebase-9ed38.appspot.com",
messagingSenderId: "117218702170",
appId: "1:117218702170:web:94a6ad8eea017273c43963",
measurementId: "G-2RN9L587XJ"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
export default firebase;
import React, { Component } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import firebase from '../database/firebase';
export default class LoginOut extends Component {
constructor() {
super();
this.state = {
uid: ''
}
}
signOut = () => {
firebase.auth().signOut().then(() => {
this.props.navigation.navigate('Login')
})
.catch(error => this.setState({ errorMessage: error.message }))
}
render() {
this.state = {
displayName: firebase.auth().currentUser.displayName, ////Firebase User Authentification /////
uid: firebase.auth().currentUser.uid
}
return (
<View style={styles.container}>
<Text style = {styles.textStyle}>
Hello, {firebase.auth().currentUser.displayName}
</Text>
<Button
color="tomato"
title="Log out"
onPress={() => this.signOut()} ///Calling Sign Out Function /////
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
display: "flex",
justifyContent: 'center',
alignItems: 'center',
padding: 35,
backgroundColor: 'wheat'
},
textStyle: {
fontSize: 15,
marginBottom: 20
}
});
Upvotes: 0
Views: 492