angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.66k stars 2.19k forks source link

Angular Universal app getting error 'location.protocol' with Firebase #2039

Closed totheskyer closed 3 years ago

totheskyer commented 5 years ago

Version info

Angular: Angular 7.1.4

Firebase: Firebase 6.5.0

AngularFire: angularfire2 5.1.2

Other (e.g. Ionic/Cordova, Node, browser, operating system): Browser application and MacOS/Windows

How to reproduce these conditions

Steps to set up and reproduce

I run Angular Universal application. It built with Angular Universal framework successfully. But when serving application in browser, i got error message. And it caused by calling a method angularFireAuth.auth.getRedirectResult().

My authentication code is:

async handleAuthRedirectResult() {
    try {
      console.log('working here');
      const userCredential: UserCredential = await this.afAuth.auth.getRedirectResult();
      console.log('working here too');
      //null means no redirect -> the page was not redirected from Auth
      if (userCredential.user) {
          //do something
      }
      else {
          return Promise.reject(e);
      }
}

Debug output

Errors in the JavaScript console

{ [Error: This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.]
  code: 'auth/operation-not-supported-in-this-environment',
  message: 'This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.' }
ERROR [Error]
ERROR [Error]

Screenshots

image

Expected behavior

It should work correctly, so need it resolved or any workaround.

jamesdaniels commented 3 years ago

Not an AngularFire issue, you need to handle the error. AF .user, .authState, .credential now all listen for .getRedirectResult so you don't have to do this yourself either.