Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

FR: Firebase Auth Lite #8284

Closed
jdgamble555 opened this issue May 31, 2024 · 11 comments
Closed

FR: Firebase Auth Lite #8284

jdgamble555 opened this issue May 31, 2024 · 11 comments

Comments

@jdgamble555
Copy link

jdgamble555 commented May 31, 2024

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

@jdgamble555 jdgamble555 added new A new issue that hasn't be categoirzed as question, bug or feature request question labels May 31, 2024
@dlarocque
Copy link
Contributor

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
Copy link
Author

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

@jdgamble555
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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)...

@jbalidiong jbalidiong added api: auth and removed new A new issue that hasn't be categoirzed as question, bug or feature request labels Jun 3, 2024
@jdgamble555
Copy link
Author

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

J

JoseVSeb added a commit to JoseVSeb/firebase-js-sdk that referenced this issue Jun 13, 2024
update browser detection logic:
detect either window or web worker (WorkerGlobalScope).

fixes firebase#8299 firebase#8284
JoseVSeb added a commit to JoseVSeb/firebase-js-sdk that referenced this issue Jun 13, 2024
update browser detection logic:
detect either window or web worker (WorkerGlobalScope).

fixes firebase#8299 firebase#8284
JoseVSeb added a commit to JoseVSeb/firebase-js-sdk that referenced this issue Jun 13, 2024
update browser detection logic:
detect either window or web worker (WorkerGlobalScope).

fixes firebase#8299 firebase#8284
JoseVSeb added a commit to JoseVSeb/firebase-js-sdk that referenced this issue Jun 26, 2024
update browser detection logic:
detect either window or web worker (WorkerGlobalScope).

fixes firebase#8299 firebase#8284
DellaBitta pushed a commit that referenced this issue Jun 28, 2024
Update browser detection logic: Detect either window or web worker (WorkerGlobalScope).
This updates the implementation to `isBrowser()` and adds a new function `isWebWorker()`.

Fixes #8299 #8284
tom-andersen pushed a commit that referenced this issue Jul 24, 2024
Update browser detection logic: Detect either window or web worker (WorkerGlobalScope).
This updates the implementation to `isBrowser()` and adds a new function `isWebWorker()`.

Fixes #8299 #8284
@DellaBitta
Copy link
Contributor

DellaBitta commented Nov 5, 2024

Hi @jdgamble555,

a change was merged a while ago to address this issue. Also we removed our dependency on undici in version 11.

Can you try out the latest version and see if this is still an issue? Thanks!

@jdgamble555
Copy link
Author

@DellaBitta - Firebase JS is working now except in Qwik, I get the Service auth is not available error:

#8506

Please look at this if you can.

J

@DellaBitta
Copy link
Contributor

Hi @jdgamble555,

Ok, thanks. I'll close this issue for now and post a reply shortly in the other issue that you've opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants