I could only find adding a new User to the project on console.firebase.google.com, giving access to all the apps it has. I want to restrict users from giving permission to specific app(s) from a project rather than creating a new project for the app. Is this feasible?
Asked
Active
Viewed 113 times
0
-
Does this answer your question? [Adding user to a single app within a firebase project](https://stackoverflow.com/questions/66156539/adding-user-to-a-single-app-within-a-firebase-project) – Dharmaraj Aug 18 '21 at 06:46
1 Answers
0
This behavior is not built in as Apps are designed for version control for the project. However, you can potentially implement this by using Custom Claims on the user. This does require a Billing Account and Cloud Functions installed. but on registration, you can call a cloud function on complete that will invoke a cloud function to add the custom claim to the user.
For example
exports.setApp= functions.https.onCall((data, context) => {
if(!data.app && ! context.auth) return;
if(!["appName1","appName2"].includes(data.app)) return;
return admin
.auth()
.setCustomUserClaims(context.auth.uid, { app: data.app})
.then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
});
// ...
});
Once this is done, you will have to refresh the user token on complete to ensure the id token has the updated claims.
You can read more about this here: https://firebase.google.com/docs/auth/admin/custom-claims

DIGI Byte
- 4,225
- 1
- 12
- 20