0

I am transitioning a ReactJS app running on Heroku to be hosted as a static site on Firebase. I am planning to use Firebase Functions to handle logic and drive environment configurations.

A requirement is to support login via 3rd-party Auth0's hosted login page -- the client is redirected to a login page via:

  // redirects to auth0's hosted login page
  this.auth0.authorize(options);

Because the options argument fed to this method depends on environment-specific configuration it should reside within a Cloud Function (according to my other question that was answered).

There is documentation in Firebase for serving dynamic content from a cloud function but I don't know how to redirect the client from a cloud function.

Is there a way I can do this? Or a more pragmatic solution?

Victor M Perez
  • 2,185
  • 3
  • 19
  • 22
TheFastCat
  • 3,134
  • 4
  • 22
  • 32
  • 1
    To redirect a client you'd do something like https://stackoverflow.com/questions/4062260/nodejs-redirect-url. But you have to seriously wonder if you want your server-side code to handle this stuff, instead of letting the client handle it. – Frank van Puffelen Feb 25 '18 at 23:53
  • I would love the client to handle it but it seems impossible since the secret config needs to reside on the server and it seems impossible to use an equivalent form of "process.env" to reference them from Firebase hosting... since Firebase hosting doesn't allow environmental variables to be specified outside of Firebase functions. – TheFastCat Feb 26 '18 at 00:05
  • 1
    Signing in with auth0 shouldn't require secrets, should it? Or is this code just redirecting the client to the specific auth0 login page for your project? – Frank van Puffelen Feb 26 '18 at 00:08
  • @FrankvanPuffelen the arguments to the method include clientId, callbackUrl etc - you are right these values are just variables and not secrets -- they can be publicly read. But I still need the ability to modify their values between environments and I can't seem to be able to do that outside of Firebase Functions -- it is the only context that allows setting such environment vars from Firebase Hosting - right? – TheFastCat Feb 26 '18 at 00:25
  • So I suppose a solution would be to create individual FirebaseFunctions to return each env variable. These functions can be defined on a per-environment basis for Dev, Staging, Prod. Lots of scaffolding but I think that can work. – TheFastCat Feb 26 '18 at 00:42
  • 1
    I'd just create a HTTP function that returns those values. Then call that from your client-side JavaScript to retrieve the config values, and apply them. – Frank van Puffelen Feb 26 '18 at 01:36
  • Thanks Frank - I'm going down that path now but ran into the issue of how to reference the firebase function endpoints themselves from each environment -- https://stackoverflow.com/questions/49054860/how-to-access-environment-specific-firebase-function-endpoints-from-firebase-hos – TheFastCat Mar 01 '18 at 16:55

0 Answers0