angularfire: SSR mode: This operation is not supported in the environment this application is running on. "location.protocol" must be http or https and web storage must be enabled

Version info

Angular: 9.1

Firebase: 7.13.2

AngularFire: 6.0.0

Other (e.g. Ionic/Cordova, Node, browser, operating system): The error happens when running ng run <project>:serve-ssr on local OS (Mac or Windows) However it seems that auth still works. So maybe this should be a warning and not an error? We can still login and everything works fine.

How to reproduce these conditions

Run Angular in SSR mode (using Nest)

Steps to set up and reproduce

I’m not really sure how to reproduce this. I believe it started appearing in our logs when we first implemented AngularFireAuth.

Debug output

** Errors in the JavaScript console **

** Angular Universal Live Development Server is listening on http://localhost:4200, open your browser on http://localhost:4200 **
Auth Failed [u [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',
  a: null
}

** Output from firebase.database().enableLogging(true); **

No output shown.

Expected behavior

Not to see the error in the log.

Actual behavior

Error in log. But nothing seems to be broken. Should this be a warning instead?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 15 (4 by maintainers)

Most upvoted comments

After updating from 6.0.2 to 6.0.3 I am no longer able to open my Ionic/Capacitor app on iOS and get the same error. I had to roll back to 6.0.2 for it to work again.

Screen Shot 2020-09-25 at 9 20 45 AM

@jamesdaniels Same for me - My Ionic/Capacitor app fails to load with the same error after using 6.0.3 (actually 6.0.3-canary.77a9a15 since I was trying to get the Analytics issue fixed). Loaded fine in 6.0.2. Hard to say what happened in 6.0.3 that’s causing this.

Amazingly, if I set server.iosScheme in capacitor.config.json to chrome-extension, the app loads perfectly fine.

I do encounter the exact same issue after upgraded to 6.0.3.

I have the same error in a newer version of Firebase

https://github.com/angular/angularfire/issues/3181

Anything helps

@jamesdaniels Im in version 7 of angularfire. I have the same issue. The browser and server build and the ssr server starts fine. but when a page is requested. then the ssr server has an error.

@firebase/auth: Auth (9.6.8): INTERNAL ASSERTION FAILED: Expected a class definition
Error: INTERNAL ASSERTION FAILED: Expected a class definition
    at debugFail (test_app/dist/apps/habitat-commons/server/main.js:317691:9)
    at debugAssert (test_app/dist/apps/habitat-commons/server/main.js:317704:5)
    at Module._getInstance (test_app/dist/apps/habitat-commons/server/main.js:317728:3)
    at new CompatPopupRedirectResolver (test_app/dist/apps/habitat-commons/server/main.js:315880:81)
    at _getInstance (test_app/dist/apps/habitat-commons/server/main.js:317736:14)
    at AuthImpl._initializeWithPersistence (test_app/dist/apps/habitat-commons/server/main.js:320082:37)
    at _initializeAuthInstance (test_app/dist/apps/habitat-commons/server/main.js:317817:8)
    at test_app/dist/apps/habitat-commons/server/main.js:325294:7
    at Component.instanceFactory (test_app/dist/apps/habitat-commons/server/main.js:325297:7)
    at Provider.getOrInitializeService (test_app/dist/apps/habitat-commons/server/main.js:327833:33)

so i looked into the _getInstance mentioned in the callstack it takes an arg should be a class instance hence the error. Here is what it looked like in my ssr bootstrap

function _getInstance(cls) {
  console.log('**((_getInstance 0))**', cls)
  debugAssert(cls instanceof Function, 'Expected a class definition');
  let instance = instanceCache.get(cls);

  if (instance) {
    debugAssert(instance instanceof cls, 'Instance stored in cache mismatched with class');
    return instance;
  }

  instance = new cls();
  instanceCache.set(cls, instance);
  return instance;
}

The log i added (see above) revealed that an error instead of a class was passed in the 3rd time. see out put below

**((_getInstance 0))** [class InMemoryPersistence] { type: 'NONE' }
**((_getInstance 0))** [class CompatPopupRedirectResolver]
**((_getInstance 0))** FirebaseError: Firebase: Error (auth/operation-not-supported-in-this-environment).
    at createErrorInternal (test_app/dist/apps/habitat-commons/server/main.js:317665:38)
    at _createError (test_app/dist/apps/habitat-commons/server/main.js:317640:10)
    at Module.2485 (test_app/dist/apps/habitat-commons/server/main.js:325381:29)
    at __webpack_require__ (test_app/dist/apps/habitat-commons/server/main.js:545206:42)
    at Module.32562 (test_app/dist/apps/habitat-commons/server/main.js:325547:76)
    at __webpack_require__ (test_app/dist/apps/habitat-commons/server/main.js:545206:42)
    at Module.70092 (test_app/dist/apps/habitat-commons/server/main.js:315550:81)
    at __webpack_require__ (test_app/dist/apps/habitat-commons/server/main.js:545206:42)
    at Module.55776 (test_app/dist/apps/habitat-commons/server/main.js:500158:79)
    at __webpack_require__ (test_app/dist/apps/habitat-commons/server/main.js:545206:42) {
  code: 'auth/operation-not-supported-in-this-environment',
  customData: {}
}
[2022-03-17T20:12:59.002Z]  @firebase/auth: Auth (9.6.8): INTERNAL ASSERTION FAILED: Expected a class definition
ERROR Error: INTERNAL ASSERTION FAILED: Expected a class definition

of course all my servers and test requests are on local host… Do you know anything that can help me understand either error

FirebaseError: Firebase: Error (auth/operation-not-supported-in-this-environment) or Error: INTERNAL ASSERTION FAILED: Expected a class definition

Thanks for confirming, I don’t have an Ionic app handy to test in. Will cut 6.0.4 final later today.

Ah! I think I know what this is, I added an await for getRedirectResult to reduce thrashing on the observable, which is probably unsupported outside of the browser. I have a work around in mind. I’ll address in a patch soon.