gpt4 book ai didi

javascript - Firebase 电话身份验证错误 : Invalid token. 在 nativeToJSError

转载 作者:行者123 更新时间:2023-12-01 11:18:01 28 4
gpt4 key购买 nike

我正在使用 firebase使用此 docs 在 native 应用程序中进行电话身份验证,我在一些不同的设备上对其进行了测试。有时电话auth有效,有时会引发此错误

firebase phone auth Error: Invalid token. at nativeToJSError



enter image description here

我已经浏览了 firebase 的文档并尝试理解这个错误。
这是我的代码片段:

confirmPhone = async(phoneNumber) => {
const phoneWithAreaCode = phoneNumber.replace(/^0+/, '+972');
return new Promise((res, rej) => {
firebase.auth().verifyPhoneNumber(phoneWithAreaCode)
.on('state_changed', async(phoneAuthSnapshot) => {
switch (phoneAuthSnapshot.state) {
case firebase.auth.PhoneAuthState.AUTO_VERIFIED:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
await this.confirmCode(phoneAuthSnapshot.verificationId, phoneAuthSnapshot.code, phoneAuthSnapshot)
res(phoneAuthSnapshot)

break

case firebase.auth.PhoneAuthState.CODE_SENT:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
res(phoneAuthSnapshot)
break

case firebase.auth.PhoneAuthState.AUTO_VERIFY_TIMEOUT:
UserStore.setVerificationId(phoneAuthSnapshot.verificationId)
UserStore.setErrorCodeAuthentication('SMS code has expired')
res(phoneAuthSnapshot)


case firebase.auth.PhoneAuthState.ERROR:
console.log(phoneAuthSnapshot.error.code)
if (phoneAuthSnapshot.error) {
this.showMessageErrorByCode(phoneAuthSnapshot.error.code)

}

rej(phoneAuthSnapshot)
break

}
})
})
}

confirmCode = async(verificationId, code, phoneAuthSnapshot) => {
console.log(verificationId, code);
try {
const credential = await firebase.auth.PhoneAuthProvider.credential(verificationId, code)
UserStore.setCodeInput(code)
UserStore.setUserCredentials(credential)
AppStore.setAlreadyVerifiedAuto(true)
await this.authenticate(credential)
return credential
} catch (e) {
console.log(e)
this.showMessageErrorByCode(e.error.code)


// throw new Error(e)
}
}

showMessageErrorByCode(errorcode) {
switch (errorcode) {
case 'auth/invalid-phone-number':
UserStore.setErrorCodeAuthentication('Please enter valid phone number');
break;
case 'auth/unknown':
{
UserStore.setErrorCodeAuthentication('User blocked by firebase');
break;
}

case 'auth/session-expired':
{
UserStore.setErrorCodeAuthentication('SMS code has expired');
break;
}
case 'auth/invalid-verification-code':
{
UserStore.setErrorCodeAuthentication('Code verification not correct');
break;
}
default:
UserStore.setErrorCodeAuthentication('other error');

}
}

authenticate = async(credential) => {
await firebase.auth().signInAndRetrieveDataWithCredential(credential)

}

//...

最佳答案

检查以下内容:

  • 正确的捆绑 ID
  • 正确的 Google-Info.plist
  • 正确的 aps-environment 值
  • 上传 APNS 身份验证 key (p8) 而不是证书

  • 希望对您有所帮助。

    关于javascript - Firebase 电话身份验证错误 : Invalid token. 在 nativeToJSError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50390534/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com