【问题标题】:The expired sms code immediately after receiving the sms收到短信后立即过期的短信代码
【发布时间】:2020-06-05 00:47:27
【问题描述】:

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

输入电话号码后,我会收到短信验证码

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

当我输入代码时,我得到代码已过期的信息

签名:第一屏

  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】:

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

    如果创建了那么还有一个问题需要解决

    您必须捕捉到用户已创建并在登录后转到屏幕

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多