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

Support On-Demand Firebase SDK Auto-configuration #890

Closed
seanlail opened this issue Apr 6, 2017 · 8 comments
Closed

Support On-Demand Firebase SDK Auto-configuration #890

seanlail opened this issue Apr 6, 2017 · 8 comments

Comments

@seanlail
Copy link

seanlail commented Apr 6, 2017

Not sure if this is even possible with AngularFire2, but this was just released:

https://firebase.googleblog.com/2017/04/easier-configuration-for-firebase-on-web.html?m=1

At first glance it seems that the init would need to be able to support this new feature from Firebase.

@davideast
Copy link
Member

@seanlail It's actually in the RC0 API which is checked in at master, but not yet released. I plan on doing a next tag release soon. See issue #854 for more details. This isn't actually a new feature it was released sometime back in November and we're just making more noise about it now.

@davideast davideast reopened this Apr 6, 2017
@davideast
Copy link
Member

Apologies, I thought you were referring to the module bundling splitting, import 'firebase/auth';

I'll have to give it a think of how we'd do it, but it would be awesome.

@Maistho
Copy link
Contributor

Maistho commented Jan 8, 2018

I solved it with a (admittedly pretty ugly) workaround:

In your index.html add the following lines before the end of the body tag (or in the head, doesn't really matter as long as they execute before the webpack bundles)

<script>
  window.firebase = { initializeApp: function(credentials) { window.firebaseCredentials = credentials} };
</script>
<script src="/__/firebase/init.js"></script>
<script>
  window.firebase = undefined;
</script>

This will save the credentials needed to initialize firebase to window.firebaseCredentials, so that we can use them when initializing the app.

Then add the saved credentials to your app.module.ts imports:

AngularFireModule.initializeApp((window as any).firebaseCredentials)

Maybe something that could be added to the docs?

@hiepxanh
Copy link
Contributor

hiepxanh commented May 5, 2018

hello, any update on this?

@jamesdaniels
Copy link
Member

No update, happy to accept a PR; which is why I left this open. Continue configuring normally for now.

@Maistho
Copy link
Contributor

Maistho commented May 6, 2018

I've been looking at where to possibly inject this in a way that is easy for users. I'd like it if it was an option to the initializeApp() call, but I don't think that it's possible without changes to the firebase SDK.
The SDK assumes that the config is provided synchronously, but if Angularfire is to be responsible for loading the config asynchronously it's not possible to do in a clean way.

I think that my solution posted above is a good fit for users who want to do this, and could probably be added (with some changes for clarity) to the docs.

It will however slow down the loading of the app slightly (one more non-deferred network request) so I don't think it should be the default/preferred way of doing it.

TL:DR; I don't think this is possible in a user-friendly way without changes to the firebase SDK to allow loading config async.

@jamesdaniels
Copy link
Member

Further, I don't think we can handle this easily with Angular Universal. I'm going to think on this more and will reconsider in the future. Closing for now.

@LeonardoRick
Copy link

LeonardoRick commented Oct 19, 2020

Any updates here? I think This is a huge update on security and I think we should discuss better on alternatives if it's not possible to implement

@Maistho, what it credentials on this case? I tried your solution but couldn't make it work

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

6 participants