问题描述
**请帮助任何人。我无法退出 Firebase。它不断给我一个错误。下面是我的代码。 ** 我已经尝试了当前用户的认证,但是还是说当前用户对象为空,一个用户是一个对象。而且我在仪表板类中调用了这个函数,但是如果我单独调用这个 Loginout 组件,它工作正常。可能是dashboard类中的调用组件有问题,我很困惑,帮帮我?!!
// 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
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)