【问题标题】:Firebase authentication works only on localhost5000 and fail on other serversFirebase 身份验证仅在 localhost5000 上有效,在其他服务器上失败
【发布时间】: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


    【解决方案1】:

    问题与域名有关,我必须进行 firebase 身份验证并在授权域下注册我的域名,之后就可以正常工作了

    【讨论】:

    • 您是如何解决主机上的端口问题的?它只适用于我的 5000 端口。
    猜你喜欢
    • 2017-05-24
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2015-03-01
    相关资源
    最近更新 更多