I am trying to prevent storage abuse.My goal is like limit a user upload operation per day.So I deploy a storage onFinalize trigger and once a file uploladed the function detect a counter that using firestore is hit the limit or not.If is, store a millisec to CustomUserClaims like this:
//the user need to wait after this time to continue upload files (timeToUnlock = currentTime + additionalTime)
setCustomUserClaims(uid, {
timeToUnlock: 1570509112055
})
And compare in rules
allow create: if request.time.toMillis() >= request.auth.token.timeToUnlock;
But every time when setCustomUserClaims i need to logout and login client again to update claims or claims won't update it just keeping previous value.I print customClaims to console the parameter are updated but seems parameter in rules are not updated.Anyone have better idea to fix this? Because if this doesn't work i have no idea to prevent this thank for any help.
console.log((await admin.auth().getUser(uid)).customClaims);