firebase / firebase/firebase-functions
[FR] There should be a way to send custom login parameter into blocking function context
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 232
- Avg merge
- 20h 46m
- Merged PRs (30d)
- 15
Description
**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
```js
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
```js
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?
Contributor guide
Assessment
This issue has not been assessed yet.