I want to make Firestore's rule using Firebase custom token like this.
match /post/{postId}{
allow create: if request.auth.token[role] == `admin`;
allow read: if request.auth.token[role] == `admin`;
}
When a user sign up an app, I want to give her its role using cloud functions. This is here.
const functions = require('firebase-functions');
export const updateAcl = functions
.firestore.document("/members/{memberId}")
.onCreate(async(user, context) => {
await getAuth().setCustomUserClaims(user.uid, {role:'admin'});
});
The flow is here.
- A user sign up the app.
- The user will be given an role in async backend.
- Using custom claim the content will appear.
But this has a problem. Because of the timing. When the user got the role using backend's async cloud functions, the content already appeared. First time when it shows, her doesn't have her role yet. I mean before the content appear, her should have her role.
Cloud functions onCreate
doesn't have sync now.
How can we solve it?