Sim*_*n H 5 android firebase-authentication progressive-web-apps
我已经构建了一个可在浏览器中运行的 SPA,它在加载时提供了一个身份验证选项,我单击 google 登录,firebase 身份验证流程将继续,直到我拥有身份验证令牌等。
然后我可以切换 PWA 并正常使用。但是,如果我随后退出,我将无法使用 Google Auth 再次登录该应用程序 - 无论我是让 google 登录弹出窗口在应用程序中还是在 Chrome 中运行,都不会确认该应用程序,实际上它似乎崩溃了。
该问题与加载 google 登录的附加选项卡有关。根据屏幕上的对话框,Android 询问我是在 PWA 中还是在 Chrome 中打开此选项卡。无论我选择哪个选项,流程都不会完成(并且由于断开连接,我在 devtools 中看不到任何有用的东西)。
似乎唯一可行的流程是继续在 chrome 上登录,只有在登录完成后,才切换到应用程序版本。这对我来说在 StackOverflow 上写代码很好,但对我的用户来说非常复杂。
我如何开始调试这种情况: - 是否可以从 PWA 进行 Firebase 身份验证;和/或 - 是否有某种方法可以延迟 Android 弹出窗口添加到主屏幕,直到用户登录浏览器?
很高兴分享代码,这是 googlesignin 函数 - 它不做任何事情,因为我通常在等待代码中的 onAuthState 消息,并且该消息包含我需要的所有信息。
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;
// ...
});
}
Run Code Online (Sandbox Code Playgroud)
根据 @jasan 的请求,我确实根据 @bojeil 的评论找到了解决方案
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);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1868 次 |
| 最近记录: |