【发布时间】:2018-05-14 17:42:00
【问题描述】:
我使用 firebase 电话身份验证构建 react 本机应用程序 在我通过
在android中生成签名的apk之后cd android && ./gradlew assembleRelease
我用我生成的apk在我的手机上进行了测试,当我进入我的手机时什么也没发生,它返回了我的错误
错误:此应用无权使用 Firebase 身份验证。请确认在 firebase 控制台中配置了正确的包名称和 sha-1。
但是 当我在没有 apk 的情况下运行应用程序时,使用
react-native run-android
身份验证效果很好,我注册了用户。
confirmPhone = async (phoneNumber) => {
const phoneWithAreaCode = phoneNumber.replace(/^0+/,'+972');
return new Promise((res, rej) => {
firebase.auth().verifyPhoneNumber(phoneWithAreaCode)
.on('state_changed', async (phoneAuthSnapshot) => {
console.log('phone-->',phoneAuthSnapshot)
switch (phoneAuthSnapshot.state) {
case firebase.auth.PhoneAuthState.AUTO_VERIFIED:
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)
// if(NavigationStore.CurrentRoute == 'Login'){
// UserStore.setErrorCodeAuthentication('Please enter valid phone number')
// }else
// UserStore.setErrorCodeAuthentication('Pin code invalid')
rej(phoneAuthSnapshot)
break
}
})
})
}
confirmCode = async (verificationId, code, phoneAuthSnapshot) => {
try{
const credential = await firebase.auth.PhoneAuthProvider.credential(UserStore.verificationId, code)
UserStore.setCodeInput(code)
UserStore.setUserCredentials(credential)
AppStore.setAlreadyRegister(true)
await this.authenticate(credential)
return credential
} catch(e){
throw new Error(e)
}
}
authenticate = async (credential) => {
await firebase.auth().signInAndRetrieveDataWithCredential(credential)
}`
【问题讨论】:
标签: android firebase react-native