我在reactNative中处理setState()时遇到问题。
在“登录”模块中,我需要在Firebase中检查“用户名”是否与电子邮件地址相关联。如果是这种情况,则对用户进行身份验证。如果没有,我会发出警报,提示“用户名与电子邮件不匹配。
所以,我有什么问题?当用户名不依赖电子邮件时,它将起作用,并显示一个警报对话框。当用户名与电子邮件匹配时,它<>起作用,当我单击按钮“连接器”时,它仍然显示警报。
我该如何解决我的代码中的此问题?
class ModalLogin extends React.Component {
state = {
email: '',
password: '',
pseudo: '',
items: [],
find: '',
iconEmail: require('../Images/icon-email.png'),
iconPassword: require('../Images/icon-password.png'),
iconName: require('../Images/name.png'),
isSuccessful: false,
isLoading: false,
scale: new Animated.Value(1),
translateY: new Animated.Value(0),
top: new Animated.Value(screenHeight),
};
handleLogin = () => {
const email = this.state.email;
const password = this.state.password;
const pseudo = this.state.pseudo;
if ((pseudo != '') & (email != '') & (password != '')) {
let user_pseudo = firebase.database().ref('/users');
user_pseudo.once('value').then(snapshot => {
snapshot.forEach(el => {
if (
pseudo === el.val().username &&
email.toLowerCase() === el.val().email
) {
this.state.find = true;
this.setState({find: true}, () => {
this.setState({isLoading: true});
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.catch(error => {
if (error.code === 'auth/user-not-found') {
this.handleSingin().bind(this);
} else Alert.alert('Error', error.message);
})
.then(response => {
this.setState({isLoading: false});
if (response) {
// Successful
this.setState({
isSuccessful: true,
});
//storage
this.storeName(this.state.user);
//this.fetchUser();
this.props.updateName(this.state.user);
setTimeout(() => {
Keyboard.dismiss();
this.props.closeLogin();
this.setState({
isSuccessful: false,
});
}, 1000);
}
});
this.setState({isLoading: false});
});
}
});
});
if (this.state.find == false) {
Alert.alert('Le pseudo ne correspond pas à son adresse email !');
// it means no username corresponds to this email address
}
} else {
console.log('erreur null');
Alert.alert(
'Error',
"login/password don't match!",
);
}
};
先谢谢您!
我在reactNative中处理setState()时遇到问题。在“登录”模块中,我需要在Firebase中检查“用户名”是否与电子邮件地址相关联。如果是这种情况,则对用户进行身份验证。 ...