Skip to content

Server App Not Logging In #8355

Closed
Closed
@jdgamble555

Description

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:

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 get this error on my server logs:

"FirebaseServerApp could not login user with provided authIdToken: ",
"FirebaseError: Firebase: Error (auth/network-request-failed)."

I thought everything was working with:
#8299
Because I didn't get a compile error, but I didn't actually run these two lines:

const serverAuth = getAuth(serverApp);
await serverAuth.authStateReady();

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

Activity

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions