Skip to content

[FR] There should be a way to send custom login parameter into blocking function context #1451

Open
@Thaina

Description

@Thaina

Is your feature request related to a problem? Please describe.
Since firebase function support blocking functions. I wish to have logic to set session claims or reject signin based on session context. Such as the current page or domain user currently used to signing in

Describe the solution you'd like
In client, I wish that the api auth().signInWithPopup and similar function should support adding custom parameter, such as

auth().signInWithPopup(new auth.GoogleAuthProvider(),{ customKey : 1234 });

Then in the server api, I wish that the AuthEventContext parameter at the API functions.auth.user().beforeSignIn should have params value being set as the custom value

exports.checkClaimBeforeSignIn = functions.auth.user().beforeSignIn((user,context) => {
    // get sessionClaims only in the page that set customKey as 1234
    if(context.params.customKey == 1234)
    {
         const doc = await getFirestore().collection("users").doc(user.uid).get();
         const adminLevel = doc.get("adminLevel");
         // get sessionClaims only in the page that set customKey as 1234
         if(adminLevel > 0)
             return { sessionClaims: { adminLevel : doc.get("adminLevel")  }  };

         // reject access to admin page
         throw new Error("Not admin");
    }
});

I don't know any workaround that could utilize blocking function this ways, is it possible?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions