收到短信后立即过期的短信代码

问题描述 投票:1回答:1

我有一个可以通过电话号码登录的应用程序

输入电话号码后,我收到一条短信代码

打开一个新屏幕,我可以在其中输入此代码

输入代码后,我会得到有关代码已过期的信息

Sign:第一屏幕

  onSignIn() {
    const {code, phoneNumber} = this.state;
    const newNumber = '+' + code + phoneNumber;
    if (newNumber.length > 10) {
      firebase
        .auth()
        .signInWithPhoneNumber(newNumber)
        .then(confirmResult => {
          this.setState({result: confirmResult});
          const navigateAction = NavigationActions.navigate({
            routeName: 'SecurityCode',
            params: {phoneAuthResponse: confirmResult},
          });
          this.props.navigation.dispatch(navigateAction);
        })
        .catch(error => {
          if (error.message === 'TOO SHORT') {
            alert('Please enter a valid phone number');
          } else {
            alert(error.message);
          }
        });
    } else {
      alert('Please Enter Your Number');
    }
  }

确认:第二个屏幕

  onConfirmCode() {
    const {securityCode} = this.state;
    if (securityCode.length > 5) {
      this.props.navigation.state.params.phoneAuthResponse
        .confirm(securityCode)
        .then(async user => {
          const ref = firebase.database().ref(`users/${user.uid}`);
          ref.once('value', async snapshot => {
            let data = snapshot.val();
            if (!data) {
              this.props.navigation.navigate('CreateProfile', {
                user: {uid: user.uid, phone_number: user.phoneNumber},
              });
            } else {
              this.props.reduxLoginUser(data);
              this.props.navigation.navigate('InviteContacts');
            }
          });
        })
        .catch(error => console.warn(error.message));
    } else {
      alert('Please enter the 6 digit code');
    }
  }

做错了什么?

android ios firebase react-native firebase-authentication
1个回答
0
投票

检查是否已创建用户(您可以在Firebase项目页面上执行此操作)

如果创建了它,那么还有另一个要解决的问题

您必须捕获到已创建用户并登录后进入屏幕

© www.soinside.com 2019 - 2024. All rights reserved.