【问题标题】:react native firebase phone auth not works after generating signed APK生成签名的APK后反应本机firebase电话身份验证不起作用
【发布时间】: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


    【解决方案1】:

    如果你还没有弄清楚,我遇到了同样的问题。

    1. 打开Android Studio
    2. 点击右侧的Gradle任务栏
    3. 在 [您的应用名称] > 任务 > android > 签名报告中双击 signingReport
    4. 记下生成的 Variant: Relase SHA-1。它应该是任务最先输出的。
    5. 将此 SHA-1 附加到 firebase 控制台中的 SHA-1 列表中。您现在应该有 2 个,一个用于调试,一个用于发布。
    6. 下载新的 google-services.json 并将其放在您的 android/app 目录中。
    7. 重建发布应用程序。

    【讨论】:

      【解决方案2】:

      转到您签名的 apk 所在的文件位置。

      1.Opem cmd并写入

      keytool -printcert -jarfile app-release.apk
      

      2.复制 SHA1 并附加到 Firebase 控制台。

      它在我的情况下有效

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-30
        • 2017-04-13
        • 1970-01-01
        • 2020-07-16
        • 2020-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多