firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.82k stars 885 forks source link

FR: Firebase Auth Lite #8284

Open jdgamble555 opened 3 months ago

jdgamble555 commented 3 months ago

Operating System

Windows 11

Browser Version

Chrome Version 125.0.6422.141

Firebase SDK Version

10.12.2

Firebase SDK Product:

Auth

Describe your project's tooling

All JS Frameworks hosted on Bun, Deno, Vercel Edge, or Cloudflare.

Describe the problem

Currently, you can only use Firebase on non-node runtimes by using "Firestore Lite." This means you have to use Firestore Lite when hosting on a Bun, Deno, Vercel Edge, Cloudflare etc server. However, there is currently no way to login using "Firestore Lite," as it requires Firebase Auth. Firebase Auth cannot be run on these servers, while technically Firestore (with REST API) can.

There needs to be a way to login on the server in these environments. This is crucial for non-serverless environments. We don't like cold starts.

Steps and code to reproduce issue

Try hosting any "Firestore Lite" app on one of these servers and using "Firebase Auth" to login server side. At the very very minimum, there should be a way to pass the token from the client the server and login with a method like "signInWithCustomToken".

However, a "Firestore Auth Lite" package that works with FirebaseServerApp and uses the AUTH REST API instead of "fs", "stream", "child_process", "crypto", "os", etc... These are usually items that are required with grpc or protobuf protocol that cause problems.

There is currently no way to host Firebase in these environments and get past the login firewall. There is currently no way to use "Firestore Lite" with a logged in user in these environments.

J

dlarocque commented 3 months ago

Hi @jdgamble555, thanks for the feature request!

I am not familiar with Deno and Bun, so I have a quick question: What is missing from Deno and Bun that is preventing users from using Auth as they would in Node?

jdgamble555 commented 3 months ago

Generally speaking all NodeJS dependencies like "os" "fs" "crypto" etc etc...

jdgamble555 commented 3 months ago

If there were something like:

import { getAuth } from "firebase/auth/lite";

And it only used the Firebase REST Auth API, that would theoretically solve the problem.

J

hsubox76 commented 3 months ago

Generally speaking all NodeJS dependencies like "os" "fs" "crypto" etc etc...

At a quick glance I don't think I can find auth code using any of those Node APIs. Specifically, what happens when you try to use firebase/auth in these environments? What errors do you get?

I looked through auth's dependencies and I do see a dep on undici which might call some native Node APIs not available in edge environments? This will probably be solved when we stop supporting Node <18 and start using native fetch, enabling us to remove the undici dep.

jdgamble555 commented 3 months ago

That is definitely one. I will see if I can run a test this weekend if there is more than just undici. When will Node 18 support stop?

jdgamble555 commented 3 months ago

I'm still trying to test this on Cloudflare, but I notice initializeServerApp thinks Cloudflare is a browser environment on this line.

throw ERROR_FACTORY.create(AppError.INVALID_SERVER_APP_ENVIRONMENT);

This is due to how isBrowser() functions are searching for the self object on this line.

The easiest fix for this would be to check for window instead:

function isBrowser(): boolean {
  return typeof window !== 'undefined';
}

J

jdgamble555 commented 3 months ago

I'm also getting "Service auth is not available" from this line. I'm not quite sure what it is checking for. However, this is only when using Qwik.

Still testing different frameworks on Cloudflare (which is also what Vercel Edge uses)...

jdgamble555 commented 3 months ago

@hsubox76 - Do you think you guys could fix the isBrowser() code? That itself might fix the problem.

J