Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase authentication works only on localhost5000 and fail on other servers

I'm new to firebase was tryn to login with google and it works fine on localhost:5000 when I use (firebase serve) but when I try to use vsCode server or github pages it doesn't work just google page popup and desapears very quickly without signing in

this is the code for login and log out

        (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();
    };
  }
})();
like image 755
sirH Avatar asked Oct 27 '25 16:10

sirH


1 Answers

the problem was related to the domain name I had to go to firebase authentication and register my domain name under the Authorised domains works fine after that

like image 149
sirH Avatar answered Oct 30 '25 14:10

sirH