React-redux-firebase: Delayed initialization

Created on 24 Feb 2017  Â·  9Comments  Â·  Source: prescottprue/react-redux-firebase

I would like to initialize firebase after user logs in in our app. In the old version of our app we use custom authentication and authenticated user can fetch firebase config from our api (apiKey, databaseUrl, authDomain) so we don't have to hardcode it in the frontend app.

Is there a way how to achieve this? I checked the source code and it looks that fbConfig is required in reactReduxFirebase and I didn't find a way how to set config values dynamically.

question

All 9 comments

Injecting a reducer using an injectReducer function (common pattern with async loading of routes) is probably possible:

export const injectReducer = (store, { key, reducer }) => {
  store.asyncReducers[key] = reducer; // eslint-disable-line no-param-reassign
  store.replaceReducer(makeRootReducer(store.asyncReducers));
};

Not sure if this pattern would be usable for injecting the reducer, but there is still the issue of adding the middleware. I will have to do some more research to look into the possibility of supporting delayed initialization.

Is there a reason to not hardcode the info on the client? Is it due to wanting to point to different Firebase instances in different environments? If so, I could potentially be of some help on that front since I have experience setting up and running quite a few multi-environment setups in production that each point to different Firebase instances.

Yup, that is the case and I also didn't want to expose firebase info
without signing in to our app (it's administration). I ended up using env
variables. It works but it's not ideal bc I have to set them for each
environment. Before I set just one thing - api url. And it is now public so
everyone who opens the login screen can see url of our firebase and can
take a look at it's public data. Again not a big deal but I would rather
not expose it:).
On Fri, 24 Feb 2017 at 19:16, Scott notifications@github.com wrote:

Injecting a reducer using an injectReducer function (common pattern with
async loading of routes) is probably possible:

export const injectReducer = (store, { key, reducer }) => {
store.asyncReducers[key] = reducer; // eslint-disable-line no-param-reassign
store.replaceReducer(makeRootReducer(store.asyncReducers));
};

Not sure if this pattern would be usable for injecting the reducer, but
there is still the issue of adding the middleware. I will have to do some
more research to look into the possibility of supporting delayed
initialization.

Is there a reason to not hardcode the info on the client? Is it due to
wanting to point to different Firebase instances in different environments?
If so, I could potentially be of some help on that front since I have
experience setting up and running quite a few multi-environment setups in
production that each point to different Firebase instances.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/prescottprue/react-redux-firebase/issues/70#issuecomment-282363647,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAmHICawEcBpbjQQ2wP23CfenQdlcNlZks5rfx58gaJpZM4MK5ym
.

Your Firebase config should be ok to have exposed since it is for a client to authenticate to begin with. Beyond that, you can have roles or an approved: true parameter on your user profiles to limit user access to your whole application or just parts of it.

I might be a little more help over gitter so I can get a better understanding of what you are going for.

How did you solve this? I have the same problem ..

I am facing a similar issue, I need to fetch the Firebase API key from an API call to our backend and only then I can init the Firebase app.
This works in version 3.0.0-alpha.3 (perhaps by accident?). I can initialize the app wrapped in the ReactReduxFirebaseProvider without providing an API key in the config, and call firebase.initializeApp(config) once I have the API key.

In versions 3.0.0 and 3.0.6 it seems to have stopped working. My app crashes on loading with this error:
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
Seems like I need to stay with 3.0.0-alpha.3 for now, until a solution is introduced.

@orenk86 Interesting... I am interested to hear the reasoning behind dynamically loading the API key. If you want to open up a new issue a description and code for reproduction, we can look more deeply to see what changed to cause the issue

@prescottprue Specifically for the API key, this is due to security requirements in my organization.

But ideally in the future we would like to have the entire configuration fetched from the backend and loaded dynamically so we can have full flexibility, as we only log in and connect to the database when we need to, and we might decide to split the data across multiple databases.

Anyway no problem, I'll open a separate issue and we can discuss everything there.
Needless to say I'll try to help in any way I can.

@orenk86 any update on this? :) I'm trying to achieve the same thing.

@dabo248 unfortunately no, I got caught up in more urgent things and eventually forgot about this.
Thanks for reminding me, I'll open an issue now :)

Was this page helpful?
0 / 5 - 0 ratings