firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.6k stars 357 forks source link

[FR] - Firebase Admin Lite #2572

Open jdgamble555 opened 1 month ago

jdgamble555 commented 1 month ago

Is your feature request related to a problem? Please describe. Currently Firebase cannot run on Deno, Cloudflare, Vercel Edge, or Bun (among others). Firebase will mainly be used in Node Serverless environments with Cold Starts, which are unacceptable for many app developers.

Describe the solution you'd like If you don't require Authentication, you can use the "Firestore Lite" package. However, we cannot use Authentication or the Server Functions in order to keep our session. This is a HUGE problem and limits where Firebase can be deployed.

Describe alternatives you've considered Using the REST API. However, it is EXTREMELY cumbersome in order to convert JSON data to the data types that REST API uses, as well as the problems handling tokens etc.

Additional context

It would be nice to be able to use the FirebaseServerApp as well, but this would not have ALL the features we may need in other JS environments.

J

google-oss-bot commented 1 month ago

I found a few problems with this issue:

dconeybe commented 4 weeks ago

@jdgamble555 Thank you for raising this issue. Could you elaborate on the use case where the preferRest option (as noted in https://github.com/firebase/firebase-admin-node/issues/1879) does not solve your issue?

jdgamble555 commented 4 weeks ago

Yes, this will not solve the problem as "Edge" computing cannot load packages like "fs", "stream", "child_process", "crypto", "os", etc... This are usually items that are required with grpc, protobuf protocol etc... but NOT with REST API.

J

jdgamble555 commented 4 weeks ago

setting preferRest still loads these items

dconeybe commented 4 weeks ago

Ok I think I see what you're saying. Could you mention which Firebase products specifically would be useful to you in a "lite" SDK? You mentioned Firestore for one. Also, would you prefer a "tree-shakeable" API (like https://github.com/firebase/firebase-js-sdk) or an object-oriented API (like https://github.com/firebase/firebase-admin-node)?

In any case, this is a pretty big undertaking so I have no promises as to if, or when, such a product will become available. But it's helpful to gather yours (and others') requirements for a time when we decide to scope such a project.

dconeybe commented 4 weeks ago

Also, could you describe how you would envision authentication to work? Authentication in the firebase-node-admin SDK in non-google edge computing environments would likely need an "exported service account key file" (https://firebase.google.com/docs/admin/setup) and these environments often do not have access to the file system. Would it work, for example, to be able to specify the JSON contents of the key file rather than a path to the key file? Then, at runtime, the code would need to first obtain the key file from some other place (e.g. d1/kv/r2 in cloudflare workers) and specify it to the initialization function for Firebase.

jdgamble555 commented 4 weeks ago

Here is how I setup my Firebase Admin app now. I use the environment variables.

Firestore already has a "lite" version that works with the REST API. It will work on non-node runtimes. However, it is only Firestore (not Firebase Auth etc) so you can't use an authentication token nor fetch data behind Firestore Rules.

Here is an example of a package that tries to mimic what Firebase Admin should already do.

https://github.com/Moe03/firebase-admin-rest

I have seen enough of these packages built over the years, that they never keep up-to-date. This is how it should work out-of-the-box IMO.

Imagine:

import { getAuth } from 'firebase-admin/auth/lite';
import { getFirestore } from 'firebase-admin/firestore/lite';

Similar to how the frontend works.

J

dconeybe commented 4 weeks ago

@jdgamble555 Thank you for the explanation and the example from @Moe03. I've logged b/343978422 internally to track this feature request and will keep you apprised of developments. But TBH it's unlikely that this feature request will see much progress without more requests from the community. For anyone who would like to see this feature, please reply with a brief explanation of your use case to help us prioritize this!

ganey commented 3 weeks ago

Wow this is still an ongoing issue? (i got the notification from the previous one with GRPC slow init)

iirc last time i used the admin sdk, preferRest was firebase/firestore only, so making one call to do an admin function meant the request took about 8 seconds in cloud functions/aws lambda.

If your doing firebase auth with a backend like php (no firebase sdk), then you could be using a node based admin app to handle this, and loading the admin sdk was just always slow.

8 seconds for a user is just ridiculous, and the early solutions such as 'function keep alive / warmers' are really not dev friendly...

'oh hey our sdk is massive and takes a while to load, so spend more money with us keeping your code cached and it'll be fast'.

Sorry if i come across annoyed by this, but I had many issues with firebase over the years from bad/missing/stale docs, to issues like this just taking forever to get fixed.

Rizzist commented 3 weeks ago

hoping new firebase admin lite works on edge when compiling regularly it works, but when compiling for edge I get this error: Module not found: Can't resolve './build/Debug/farmhash.node'

^guessing its a firebase dependency?

kulterryan commented 1 week ago

how to use it with Bun?

dconeybe commented 1 week ago

Note that this repository specifically targets node (the name is firebase-admin-node). Providing a version that works portably across JavaScript runtimes (e.g. deno, bun, cloudflare workers) is a significant undertaking to create and maintain long-term and not something that is prioritized at the moment. That being said, please continue to voice your interest in such an SDK so that we can get a sense of the customer demand for this feature. Thanks everyone!

jdgamble555 commented 1 week ago

@dconeybe - To be fair, it was built for Node before other Runtimes were popular and probably named to differentiate between go, python etc.

It would be advantageous to build a "lite" version, just like firebase-js-sdk has, as it could speed up NodeJS loading times as well. I don't think you would need to rebuild the whole package, just allow more tree-shaking and less dependency needs per package. If you imported from firebase-admin/lite for example, it would not import all the bulk package dependencies etc.

J

dconeybe commented 1 week ago

@jdgamble555 Thank you for your input. I don't disagree that there is value in providing a version that is decoupled from node.js. It's just a matter of prioritization.