使用电子邮件创建用户的 Firebase 身份验证

时间:2020-12-29 16:16:18

标签: react-native

我正在尝试使用 createUserWithEmailAndPassword 构建身份验证。它不断抛出这个错误 firebase.auth 不是函数。 (在 'firebase.auth()' 中,'firebase.auth' 未定义

registerUser = () => {
    if (this.state.email === '' && this.state.password === '') {
      Alert.alert('Enter details to signup!');
    } else {
      this.setState({
        isLoading: true,
      });
      firebase
        .auth()
        .createUserWithEmailAndPassword(this.state.email, this.state.password)
        .then((res) => {
          res.user.updateProfile({
            displayName: this.state.displayName,
          });
          console.log('User registered successfully!');
          this.setState({
            isLoading: false,
            displayName: '',
            email: '',
            password: '',
          });
          this.props.navigation.navigate('Login');
        })
        .catch((error) => this.setState({errorMessage: error.message}));
    }
  };

0 个答案:

没有答案