Я пытаюсь, чтобы пользователь подтвердил свою учетную запись, используя код подтверждения.Я хочу получить пользовательский документ из базы данных firestore, проверить, чтобы код аутентификации соответствовал предоставленному значению, а затем изменил поле hasVerfied документа на True.
Это для мобильного приложения (на устройстве, а не на стороне сервера), поэтому я не могу использовать firebase-admin ... У меня появляется экран, но как только я заполняю поле аутентификации, нажмите кнопку без действияпроисходит, но я могу подтвердить, что функция определенно достигается, но не выполняет код из-за какой-то ошибки.
handleConfirmation = () => {
const auth_code = this.state.authCode;
let user = firebase.firestore().collection('users').where('uid', '==', firebase.auth().currentUser.uid);
// ^ I am not sure if this is correct... could be a source of wrongness.
if (user.exists === true) {
console.log(user.data());
let user_to_verify = user.data();
const has_verified = user_to_verify.hasVerified;
if (has_verified === false) {
const user_auth_code = user.authCode;
if (auth_code === user_auth_code) {
console.log("User verification code is correct");
this.setState({hasVerified: true});
this.updateUser();
// ^ this function should set the
// value of user.hasVerified to True, and
// save it in firestore (aka firebase firestore)
//
// Now the user can successfully login to app
}
}else{
// user doesnt exist... throw error and exit
}
при отправке формы (onPress кнопки в приложении) выполняется handleConfirmation, и код auth_code сравнивается с user_auth_code (который является значением поля authCode из документа пожарной базы firebase), если эти значения совпадают, поле hasVerified пользователя изменяется на True и сохраняется в firebase.
Пожалуйста, помогите!К вашему сведению, это моя первая публикация на StackOverFlow, поэтому дайте мне знать, если я следовал соответствующим инструкциям.
// РЕДАКТИРОВАТЬ: показывает, как я инициализирую пользователей при создании.
constructor() {
super();
this.ref = firebase.firestore().collection('users');
this.state =
{
firstname: '<first name>',
lastname: '<last name>',
email: '<email>',
password: '<password>',
errorMessage: '<none unless error occurs>',
secureTextEntry: true,
confirmPassword: '<password>',
modalVisible: false,
imageURI: '<some url>',
authCode: '<authentication code>',
hasVerified: false,
};
this._keyboardDidHide = this._keyboardDidHide.bind(this);
this.setDate = this.setDate.bind(this);
}
.
. // SKIPPED SOME IN-BETWEEN LINES FOR BREVITY
.
updateUser() {
let user_data = {
uid: firebase.auth().currentUser.uid,
firstname: this.state.firstname,
lastname: this.state.lastname,
email: this.state.email,
imageURI: this.state.imageURI,
authCode: this.state.authCode,
hasVerified: this.state.hasVerified,
};
console.log(user_data);
this.ref.doc(firebase.auth().currentUser.uid).set(user_data);
this.props.navigation.navigate('homescreen');
}