【发布时间】:2020-05-26 20:16:21
【问题描述】:
我是 firebase 的新手,曾尝试使用 google 登录,当我使用 (firebase serve) 时它在 localhost:5000 上运行良好,但是当我尝试使用 vsCode 服务器或 github 页面时,它仅适用于 google 页面弹出窗口并在没有登录的情况下很快消失
这是登录和注销的代码
(function() {
"use strict";
angular.module("app").controller("logInCtrl", logInCtrl);
// inject $firebaseAuth
logInCtrl.$inject = ["$firebaseAuth"];
function logInCtrl($firebaseAuth) {
let $ctrl = this;
let firebaseAuthObj = $firebaseAuth();
//login function
$ctrl.logIn = function() {
firebaseAuthObj.$signInWithPopup(new firebase.auth.GoogleAuthProvider());
};
}
})();
(function() {
"use strict";
angular.module("app").controller("mainCtrl", mainCtrl);
// inject $firebaseAuth
mainCtrl.$inject = ["$firebaseAuth"];
function mainCtrl($firebaseAuth) {
let $ctrl = this;
let firebaseAuthObj = $firebaseAuth();
// watcher on main ctr it will load once website starts and will show the state for login
firebaseAuthObj.$onAuthStateChanged(function(user) {
if (user === null) {
$ctrl.user = user;
} else {
$ctrl.user = user.displayName;
}
console.log("authStateChanged", user);
console.log($ctrl.user);
if (user) {
console.log("Welcome UID:" + user.uid);
}
});
// signout function
$ctrl.logOut = function() {
firebaseAuthObj.$signOut();
};
}
})();
【问题讨论】:
标签: angularjs firebase-authentication firebase-hosting