angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Uncaught Error: "location.protocol" must be http or https when building to device using Ionic 2 & Angular 2

Open redolds opened this issue 10 years ago • 48 comments

Error in question: This operation is not supported in the environment this application is running on. "location.protocol" must be http or https.

This error only occurs when the app is built & running on a device. In the browser it works great (which is logical).

Maybe there's a way to manually set the location.protocol on a cordova app using Ionic 2?

redolds avatar Jun 18 '16 19:06 redolds

here is a project where I am running into issues - https://github.com/aaronksaunders/ionic2-angularfire-sample/tree/firebase3-support

Issue appears to be around anything that you need to subscrbe to, I am creating a very basic app to demonstrate the issue.

I am getting errors thrown around this.af.auth.subscribe()

I created a smaller project that shows the issue without all the extras: https://github.com/aaronksaunders/basicaf2

aaronksaunders avatar Jun 19 '16 00:06 aaronksaunders

Has anyone found a way around this error? Seems like this error is making angularfire useless for cordova apps.

Chuckv01 avatar Jun 21 '16 04:06 Chuckv01

Facing same issue !

aamir1995 avatar Jun 21 '16 06:06 aamir1995

As @aaronksaunders said, it has to do with .subscribe().

Whenever you subscribe to a method from firebase, this is including their FirebaseListObservable's this location.protocol issue occurs.

and yeah, @Chuckv01 having the same issue here, switched my app to use localStorage for & probably going to use another Authentication provider or service unless they fix this issue rapidly (easy to switch services).

redolds avatar Jun 21 '16 08:06 redolds

Can use previous versions of AngularFire to avoid this issue? Need to wait until they fix it.

mithunvp avatar Jun 21 '16 09:06 mithunvp

@mithunvp yes, you can use previous version of AngularFire 2 with Firebase SDK v2.4.2, Until they fix this issue.

aamir1995 avatar Jun 21 '16 09:06 aamir1995

With Firebase SDK 2.4.2, I will have to use legacy Firebase site not the new firebase.google.com site, I am little confused here?

mithunvp avatar Jun 21 '16 09:06 mithunvp

True, you have to use legacy Firebase console :( :(, but it's a matter of some days until they figure it out.

aamir1995 avatar Jun 21 '16 09:06 aamir1995

I believe this issue is in the Firebase SDK itself, since the AngularFire2 codebase doesn't access location at any point.

@aaronksaunders or @nickkenens can either of you try using the new Firebase SDK without AngularFire2 and see if the problem still occurs?

I'll see if I can run @aaronksaunders project to repro the issue.

jeffbcross avatar Jun 22 '16 01:06 jeffbcross

@jeffbcross i just tried it with the just the Firebase SDK and it works fine...

aaronksaunders avatar Jun 22 '16 02:06 aaronksaunders

Thanks I wasn't able to get the reproduction running before I left the office, could someone post a full stack trace here? On Tue, Jun 21, 2016 at 7:02 PM Aaron K Saunders [email protected] wrote:

@jeffbcross https://github.com/jeffbcross i just tried it with the just the Firebase SDK and it works fine...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/243#issuecomment-227623404, or mute the thread https://github.com/notifications/unsubscribe/AAcTVxBW6bPbmrn5iIHJ1yf3UMdzRCoUks5qOJezgaJpZM4I5A1i .

jeffbcross avatar Jun 22 '16 02:06 jeffbcross

I have traced up to firebase.js. Seems it is a problem with SDK - it checks protocol to be http or HTTPS and in ionic2 environment protocol is file://

However I did not checked with pure SDK as @aaronsaunders did. Strange - may be we are using different GB SDKs...

olostan avatar Jun 22 '16 03:06 olostan

This issue also don't allow to use Firebase authentication... It is really critical for my app. Any workarounds?

olostan avatar Jun 22 '16 10:06 olostan

Facing the same issue with Ionic v1

alexissusset avatar Jun 22 '16 15:06 alexissusset

Found the issue: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#getRedirectResult

The error is listed on that page.

Auth is calling that method to see if the app is being loaded as an oauth redirect. We could add a protocol check before calling the method.

jeffbcross avatar Jun 22 '16 16:06 jeffbcross

I have same error when trying auth with pop-up, not reflect. That should work (and was working on previous SDK) on Ionic2...

olostan avatar Jun 22 '16 19:06 olostan

@olostan the error occurs as soon as subscribing to auth because AngularFire is calling getRedirectResult() under the covers to check if the request is part of a redirect oauth flow.

jeffbcross avatar Jun 22 '16 19:06 jeffbcross

I've published a preview of the changes I made in #271 to npm. Can folks here please npm install angularfire2@next and check that this issue is resolved?

Note: this has been published with the next tag on npm, so including the @next is required in order to install the correct version.

jeffbcross avatar Jun 22 '16 19:06 jeffbcross

@jeffbcross just checked it and it works

aaronksaunders avatar Jun 22 '16 19:06 aaronksaunders

@jeffbcross I updated to angularfire2@next and it looks like the error is fixed on auth.subscribe(). However, the error is still happening on auth.login().

Here is the code where I am seeing the location.protocol error occur on iOS and Android devices:

this.af.auth.login({
  provider: AuthProviders.Google,
  method: AuthMethods.Popup
}).then((value) => {
  //success
}).catch((error) => {
  this.errorAlert(error);
});

Sorry if I am missing something :)

Chuckv01 avatar Jun 23 '16 20:06 Chuckv01