Ionic4 Firebase Google Auth跨平台无法正常工作

时间:2020-07-11 21:50:21

标签: javascript reactjs typescript firebase firebase-authentication

在两个平台android和Desktop-web上使用google登录。 在Web场景中单击“登录”时,没有任何反应。

在android场景中单击“登录”时,将弹出google auth面板。选择我的Gmail帐户登录后,没有任何反应。预计将重定向到主页/仪表板。

登录按钮。

<IonButton color="red" expand="full" onClick={googleLoginWebOrMobile} >
                                    Google+
                                </IonButton>
function googleLoginWebOrMobile() {
        if(isPlatform('capacitor')) {
            return nativeGoogleLogin();
        } else {
            return webGoogleLogin();
        }
    }
    
    async function nativeGoogleLogin(){
        GooglePlus.login({
            'webClientId':'xxx.xxx.xxx',
            'offline': true
        }).then(async res=>{
            await firebase.auth().signInWithCredential(firebase.auth.GoogleAuthProvider.credential(res.idToken)).
            then(succes=>{
                history.replace('/home/dashboard')
                history.go(history.length)
                toast("Logare cu succes!")
            }).catch(ns=>{
                toast("Logare eșuată cu Google")
            })
        })
    
    }

    async function webGoogleLogin(){
        GooglePlus.login({
            'webClientId':'xxx.xxxx.xx,
            'offline': true
        }).then(async res=>{
            const provider = new firebase.auth.GoogleAuthProvider();
            return  await firebase.auth().signInWithPopup(provider).
            then(succes=>{
                history.replace('/home/dashboard')
                history.go(history.length)
                toast("Logare cu succes!")
            }).catch(ns=>{
                toast("Logare eșuată cu Google")
            })
        })
    }

0 个答案:

没有答案