I build react native app with firebase phone auth after I generated signed apk in android by
cd android && ./gradlew assembleRelease
I tested on my phone with the apk I generated and when I enter my phone nothing happened and it return my error
Error: this app is not authorized to use firebase authentication. please verifythat the correct package name and sha-1 are configured in the firebase console.
BUT when I run the app without the apk, with
react-native run-android
and the authentication works good and I register user.
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)
}`