-
Notifications
You must be signed in to change notification settings - Fork 893
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
Server App Not Logging In #8355
Comments
Possibly related to - #8347 |
That's interesting. |
I can't pinpoint this problem. It does seem to work on Vercel Edge, but not on Cloudflare, which is interesting considering Vercel Edge is just a Cloudflare Worker. The About Page uses the Login:
Part of the problem is that there is no way to import { PUBLIC_FIREBASE_CONFIG } from "$env/static/public";
import { error } from "@sveltejs/kit";
import { initializeServerApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore/lite";
const firebase_config = JSON.parse(PUBLIC_FIREBASE_CONFIG);
export const firebaseServer = async (request: Request) => {
const authIdToken = request.headers.get('Authorization')?.split('Bearer ')[1];
if (!authIdToken) {
error(401, 'Not Logged In!');
}
const serverApp = initializeServerApp(firebase_config, {
authIdToken
});
// auth
const serverAuth = getAuth(serverApp);
await serverAuth.authStateReady();
if (serverAuth.currentUser === null) {
error(401, 'Invalid Token');
}
// db
const serverDB = getFirestore(serverApp);
return {
serverAuth,
serverDB
};
}; I'm also wondering how Firebase knows it is using an Any ideas? Thanks, J |
I am also facing the same issue. initializeServerApp working fine everywhere but fails on cloudflare edge. |
@DellaBitta - I made a minimum test project for Cloudflare. https://github.com/jdgamble555/svelte-firebase-server-test
You should get the document you just added. Instead of adding a service worker, I emulate it by passing the Bearer token manually to the endpoint for testing purposes.
You will see the problem at hand. The page will fail when you login and click "Load About with Token" Again, you wouldn't have to view server logs if there were a way to catch the actual error. J |
As a quick check, could you please see if other Auth operations such as |
The error message is caused from this line: await serverAuth.authStateReady(); Again, there should be a way to catch this error on the front end instead of server logs, so please J |
I think it's not caused by |
@DellaBitta Just tried Code
Logs
|
You're still calling When I leave that out, I get a different error: const serverApp = initializeServerApp(firebase_config, {
authIdToken
});
const serverAuth = getAuth(serverApp);
await signInAnonymously(serverAuth);
J |
@jdgamble555
|
@jimmy0251 - Exactly. What it does behind the scenes, apparently J |
@DellaBitta I did some debugging and it seems like the real error is Sentry made a similar fix here getsentry/sentry-javascript#9200. (Issue link) |
I'm sorry folks. I should have pointed out that Auth, when initialized with an instance of |
The Auth SDK does indeed set the If this is what's causing the problem for Auth when using both |
I get the same error when using: const app = initializeApp(firebase_config);
const auth = getAuth(app);
await signInAnonymously(auth);
Side note, on my Qwik Todo App version (using the same Firebase code), I'm getting this error when deploying to Vercel Edge (Cloudflare in background):
This could be a different problem all together, but just noting it here in case it is related. I can make a minimum test project later if you need me to. J |
@DellaBitta Yes, that's what causing the issue. I think the field is not required for server auth but maybe it's there because earlier the auth SDK was intended to work only in browsers. Looking forward to seeing this fixed. This is blocking us from making several components server-rendered. |
Originally you mentioned that Vercel Edge was working, here.
Is that not the case anymore? Thanks! |
Yes, Vercel Edge is working fine with SvelteKit. It just does not work with Qwik. I believe Qwik bundles a bit differently than SvelteKit, so not exactly sure why it doesn't work. I can do some more testing when I get home after work with a test app, but in case it is related, I wanted you to know the error message. |
Hi @jdgamble555, Good news / bad news. I followed your instructions to deploy a copy of your example project to Cloudflare. I tested both the use of Was there something else that you configured in Cloudflare which could have caused your deployment to run on a specific worker configuration? |
@DellaBitta - I'm not sure what you mean. In order to fully test the app, you have to click on the Try it again with the updated code (I had modified it to test
J |
@DellaBitta Thanks for the investigation. Would it be possible for you to share the demo project you made? I want to look at its Cloudflare config and will try to deploy it in my account to see if it's an account-specific issue. |
@jdgamble555 and @jimmy0251, after further tinkering and testing I was able to reproduce the problem with both |
Any update or timeline on this? Not being able to run Firestore on next.js edge runtimes is a real blocker for us. |
@DellaBitta - All you guys need to do is remove one line of code:
Is this on the horizon? I have a feeling there might be something else to fix after this, so we need to move forward to test it. Thanks, J |
@jimmy0251 @DellaBitta - While the I forgot in SvelteKit you can filter through all fetch requests, and hence remove the unwanted header with hooks. import type { Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
const modifiedRequest = new Request(event.request.url, {
method: event.request.method,
headers: event.request.headers,
body: event.request.body,
redirect: event.request.redirect,
credentials: event.request.credentials,
referrer: event.request.referrer,
mode: event.request.mode,
cache: event.request.cache,
integrity: event.request.integrity,
keepalive: event.request.keepalive,
signal: event.request.signal,
referrerPolicy: undefined
});
const response = await resolve({
...event,
request: modifiedRequest,
});
return response;
}; This solves the first problem, but now the console.log(authIdToken);
const serverApp = initializeServerApp(firebase_config, {
authIdToken
});
// auth
const serverAuth = getAuth(serverApp);
await serverAuth.authStateReady();
if (serverAuth.currentUser === null) {
// this is ALWAYS true
error(401, 'Invalid Token');
} J |
Hi @jdgamble555 and @jimmy0251, We've made a buid that removes Could you try pinning your firebase version to
According to the SvelteKit hook documentation, But thankfully we have a candidate for a fix in the canary build mentioned above. Please give it a try. Thanks! |
@DellaBitta - This looks like this fixes the problem! I guess you're right! https://svelte-firebase-server-test.pages.dev/ Thanks, J |
Great news! The change will be part of our next release. I'll update this issue when it's available. |
Version 10.13.2 has been released! I'm going to close this issue for now. If you encounter any other problem please create a new issue and mention this one within it (if it's related). Thanks folks! |
Operating System
n/a
Browser Version
n/a
Firebase SDK Version
10.12.3
Firebase SDK Product:
Auth
Describe your project's tooling
SvelteKit with Firebase - https://code.build/p/sveltekit-todo-app-with-firebase-C73xaa
Describe the problem
While running this function on a fresh login with a new token:
I get this error on my server logs:
I thought everything was working with:
#8299
Because I didn't get a compile error, but I didn't actually run these two lines:
So, my code was not using the login token to login.
I am running on Cloudflare, so I imagine this would be the same problem in Vercel Edge, NextJS Middleware, etc.
Is this due to a
fetch
problem?J
Steps and code to reproduce issue
Here is my REPO. You could clone it and use it with any Firestore instance with open rules. Just configure the
.env
file. It would need to be deployed to an edge environment.https://github.com/jdgamble555/sveltekit-firebase-deploy
The text was updated successfully, but these errors were encountered: