Firebase电话号码身份验证:用于创建电话身份验证凭证的验证ID无效

时间:2020-03-14 16:48:13

标签: javascript firebase react-native firebase-authentication

我的应用程序的用户无法再验证SMS代码以登录到该应用程序。我从服务器得到的响应是:

用于创建电话身份验证凭证的验证ID无效。

我正在使用React Native Firebase 6.3.0-以前注册帐户的用户仍可以登录。我提供使用以下功能从Firebase返回的验证ID:

export const authorizeFirebase = phoneNumber => {
  return new Promise((res, rej) => {
    firebase.auth()
      .verifyPhoneNumber(phoneNumber)
      .on('state_changed', async phoneAuthSnapshot => {
        switch (phoneAuthSnapshot.state) {
          case firebase.auth.PhoneAuthState.AUTO_VERIFIED: // or 'verified'
            const { verificationId, code } = phoneAuthSnapshot;
            const accessToken = await confirmCode(verificationId, code);
            const result = await firebase.auth().signInWithPhoneNumber(phoneNumber, true);
            res(accessToken);
            break;

          case firebase.auth.PhoneAuthState.CODE_SENT: // or 'sent'
            res(phoneAuthSnapshot)
            break;

          case firebase.auth.PhoneAuthState.AUTO_VERIFY_TIMEOUT: // or 'timeout'
            res(phoneAuthSnapshot)
            break;

          case firebase.auth.PhoneAuthState.ERROR: // or 'error'
            rej(phoneAuthSnapshot.error)
            break;
        }
      }, (error) => {
        rej(error)
      });
  })
}

export const confirmCode = async (verificationId, code) => {
  try {
    const credential = await firebase.auth.PhoneAuthProvider.credential(verificationId, code);
    const smsCodeAuthenticationResponse = await authenticate(credential);
    return smsCodeAuthenticationResponse.response;
  } catch (error) {
    return { responseType: 'error', response: error };
  }
}

const authenticate = async (credential) => {
  try {
    const { user } = await firebase.auth().signInWithCredential(credential);
    const accessToken = await user.getIdToken();
    return { responseType: 'success', response: accessToken };
  } catch (error) {
    return { responseType: 'error', response: error };
  }
}

我已经花了一整天的时间试图找出答案,但是没有任何运气。 Firebase为什么会提供无法使用的验证ID?

任何有关如何解决它的想法都将受到赞赏!

0 个答案:

没有答案