Я начинаю с response-native и пытаюсь получить пользовательские данные firebase с помощью onAuthStateChanged.
Я пытался сделать bind
this
, но до сих пор понятия не имею об этом.
это мой конструктор
constructor(props) {
super(props);
this.state = {
isUid: '',
isProvider:'',
isPhoneNumber:'',
};
и это мой onAuthStateChange в componentDidMount
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');
}
}