firebase身份验证不适用于Android桌面上安装的PWA [英] firebase auth not work with PWA installed on Android desktop

查看:57
本文介绍了firebase身份验证不适用于Android桌面上安装的PWA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个可在浏览器中使用的SPA,在加载时它提供了一个auth选项,我单击google登录,firebase身份验证流程将继续进行,直到我拥有一个auth令牌等为止.

I have built a SPA that works in the browser in that on load it provides an auth option, I click google signin and the firebase auth flow continues until I have an auth token etc.

然后我可以切换PWA并照常使用.但是,如果我随后注销,则无法使用Google Auth再次使用该应用程序登录-无论我让Google登录弹出窗口在该应用程序中运行还是在Chrome中运行,都无法确认该应用程序,实际上它似乎崩溃了.

I can then switch the PWA and use as normal. But if I then logout, I cannot log back in again with the App using Google Auth - whether I let the google signin popup run in the App or in Chrome, no confirmation ever gets abck to the App and indeed it seems to crash.

问题与Google登录的其他标签的加载有关.根据屏幕上的对话框,Android询问我是在PWA中还是在Chrome中打开此标签.无论我选择哪个选项,流程都不会完成(并且由于断开连接,我看不到devtools中有用的东西).

The issue has something to do with the loading of the additional tab for the google signin. According to the onscreen dialog Android asks me whether to open this tab in the PWA or in Chrome. Whichever option I pick, the flow does not complete (and because of the disconnection, I can't see anything useful in devtools).

唯一可行的流程是继续在chrome上登录,并且只有在登录完成后才切换到App版本.这对我来说可以在StackOverflow上写,但是对我的用户来说非常复杂.

The only flow that seems to work is to continue the login on chrome and, only when that has completed, switch to the App version. That's fine for me to write on StackOverflow but very complicated for my users.

如何开始调试这种情况: -是否有可能通过PWA进行Firebase身份验证;和/或 -在用户登录浏览器后,是否有某种方式可以延迟将Android弹出窗口添加到主屏幕的时间,直到til?

How can I begin to debug this situation: - should it be possible to do firebase auth from a PWA; and/or - is there someway to delay the Android popup to add to home screen to til after the user has logged in on the browser?

很高兴分享代码,这是googlesignin函数-它什么也不做,因为我通常在代码中等待onAuthState消息,并且该消息包含了我需要的所有信息.

Happy to share code, and this is the googlesignin function - it doesn't do anything because I wait for the onAuthState message in my code usually and that has all the information I need.

function signinGoogle() {
    var provider = new firebase.auth.GoogleAuthProvider();
    firebase.auth().signInWithPopup(provider).then(function(result) {
        // This gives you a Google Access Token. You can use it to access the Google API.
        var token = result.credential.accessToken;
        // The signed-in user info.
        var user = result.user;
        // ...
    }).catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
        // ...
    });
}

推荐答案

对于@jasan的请求,我确实找到了基于@bojeil的评论的解决方案

Per @jasan 's request, I did find a solution based on @bojeil 's comment

function signinGoogle(cb) {
    var provider = new firebase.auth.GoogleAuthProvider();
    // firebase.auth().signInWithPopup(provider).then(function(result) {
    firebase.auth().signInWithRedirect(provider).then(function(result) {
        console.log("Google signin successful")
        // This gives you a Google Access Token. You can use it to access the Google API.
        // var token = result.credential.accessToken;

        // Send user  to rest of program
        cb(token)
    })
    .catch(function(error) {
        logger(error);
    });
}

这篇关于firebase身份验证不适用于Android桌面上安装的PWA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆