Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #2570

Closed
rmcsharry opened this issue Aug 10, 2020 · 15 comments

Comments

@rmcsharry
Copy link

rmcsharry commented Aug 10, 2020

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?

@rmcsharry rmcsharry changed the title 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 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 Aug 10, 2020
@jamesdaniels
Copy link
Member

Can you try with 6.0.3? I should be guarding against using auth in SSR now.

@kyleabens
Copy link

kyleabens commented Sep 25, 2020

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 jamesdaniels reopened this Sep 25, 2020
@JumBay
Copy link

JumBay commented Sep 25, 2020

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

@tylerc
Copy link

tylerc commented Sep 25, 2020

@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.

@NLueg
Copy link

NLueg commented Oct 15, 2020

@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.

Setting the iosScheme to chrome-extension fixed the problem for me too but this destroys saved data from local storage ... is there no other solution? I have the problem with 6.0.0+ too. But version 5.4.2 works!

@stevebrowndotco
Copy link

Confirmed happening for me after updating from 6.0.0 + . Testing to see if rolling back to 6.0.0 or so fixes it.

Silent updating with ^ in package json can be a curse sometimes and this unfortunately bypassed my testing and I submitted a broken app to the app store :(

@stevebrowndotco
Copy link

stevebrowndotco commented Oct 22, 2020

OK, can confirm upgrading to 6.0.3 breaks my authentication with this error. 6.0.2 is the last stable one for me. I double checked after removing node_modules, package-lock.json and doing a fresh install. The break only happens on iOS and I am running an ionic5/ cordova application. Curiously, I don't get the error on some iOS devices.

@MirageDT
Copy link

MirageDT commented Oct 25, 2020

Getting the error in an Electron/Cordova hybrid application after upgrading.

For me, the error comes from the AngularFireAuth.user observable use. Removing it removes the error.

(PS : in case it's not clear, this is not a solution, this is a complain, I need to get the currently logged in user !)

(PS 2 : switching back to 6.0.2 resolves the issue)

@jamesdaniels
Copy link
Member

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.

@jamesdaniels
Copy link
Member

Cut 6.0.4-canary.9a26fbe which has a possible fix, hopefully it's sufficient. Please give it a try and LMK. If it works I'll cut 6.0.4 ASAP.

@kyleabens
Copy link

@jamesdaniels I can confirm that the issue has been resolved with 6.0.4-canary.9a26fbe and Firebase v8 👍

@MirageDT
Copy link

@jamesdaniels I can confirm that the issue has been resolved with 6.0.4-canary.9a26fbe and Firebase v8 👍

Thank you, I was not able to test it out :(

@jamesdaniels
Copy link
Member

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

@ohabash
Copy link

ohabash commented Mar 17, 2022

@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

@ohabash
Copy link

ohabash commented Mar 17, 2022

I have the same error in a newer version of Firebase

#3181

Anything helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants