【发布时间】:2019-07-02 19:12:03
【问题描述】:
我从 react-native 开始,并尝试使用 onAuthStateChanged 获取 firebase 用户数据。
我尝试过bindthis,但我仍然对此一无所知。
这是我的构造函数
constructor(props) {
super(props);
this.state = {
isUid: '',
isProvider:'',
isPhoneNumber:'',
};
这是我在 componentDidMount 中的 onAuthStateChange
componentDidMount() {
var user = firebase.auth().currentUser;
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
user.providerData.forEach(function (profile) {
this.setState({isProvider: profile.providerId}, console.log(isProvider)).bind(this);
this.setState({isPhoneNumber: profile.phoneNumber}, console.log(isPhoneNumber)).bind(this);
this.setState({isUid: user.uid}, console.log(isUid)).bind(this);
});
} else {
console.log('no user');
}
}
【问题讨论】:
标签: javascript firebase react-native firebase-authentication