Skip to content
New issue

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

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

Already on GitHub? # to your account

Provide better support for Google Cloud native environments #75

Closed
samos123 opened this issue Feb 15, 2021 · 3 comments · Fixed by #348
Closed

Provide better support for Google Cloud native environments #75

samos123 opened this issue Feb 15, 2021 · 3 comments · Fixed by #348
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@samos123
Copy link

samos123 commented Feb 15, 2021

Is your feature request related to a problem? Please describe.
When you run on Google Cloud, you often can rely on the default application credentials. So there isn't a need to store the private key in an environment variable. Instead it would be preferred to load the firebase admin using this code:

var admin = require('firebase-admin');
var app = admin.initializeApp();

For reference see: https://firebase.google.com/docs/admin/setup

Describe the solution you'd like and how you'd implement it
Change the behaviour such that when no firebaseAdminInitConfig is specified it will initialize the app using the following code:

admin.initializeApp()

Is this a breaking change?
Would this require existing users to change how they're using next-firebase-auth?
It wouldn't be a breaking change because existing users that have the firebaseAdminConfig will continue to work as is

I will happily provide a PR for this change if this is something that you would accept.

samos123 added a commit to samos123/next-firebase-auth that referenced this issue Feb 15, 2021
Try to load default credentials if no firebaseAdminInitConfig is
provided. This way no private key needs to be set as environment
variable.

For reference:
gladly-team#75
@kmjennison
Copy link
Contributor

This makes sense. However, I'd like to also preserve the error for the users who accidentally don't provide any credentials. Ideally:

  • If the user provided a credential, init as we currently do.
  • If the user did not provide a credential, try admin.initializeApp(). If it fails because of an invalid or missing app credential, throw the existing error (If not initializing the Firebase admin SDK elsewhere, you must provide "firebaseAdminInitConfig" to next-firebase-auth.) I'm not sure what error code the admin app uses for a failed init.

Just FYI, as a fairly straightforward workaround, you can initialize Firebase yourself before initializing next-firebase-auth. See the pattern here.

@samos123
Copy link
Author

I tried the latest version and this was working out of the box now when setting useFirebaseAdminDefaultCredential: true,. Thank you for the great library and making it work easily on GCP environments!

@kmjennison
Copy link
Contributor

Wonderful, thanks for the follow-up and kind words!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants