Skip to content

Instantly share code, notes, and snippets.

@9wick
Created January 29, 2018 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9wick/11034674f4c8c0100b845baa983fc286 to your computer and use it in GitHub Desktop.
Save 9wick/11034674f4c8c0100b845baa983fc286 to your computer and use it in GitHub Desktop.
Firebase storageでのグループ認証 ref: https://qiita.com/wicket/items/85115c4a6045f4d5fecd
{
users:{
userA : {
groups : {
groupA : true
groupB : true
}
},
userB : {
groups : {
groupB : true
groupC : true
}
}
}
}
exports.updateUserGroupGrant = functions.database.ref('/users/{userId}/groups')
.onWrite(event => {
return refreshCustomClaims(event.params.userId);
});
function refreshCustomClaims(userId){
return admin.database().ref('/users/' + userId + "/groups").once('value').then((snapshot) => {
var claim = {};
for (var key in snapshot.val()){
claim[key] = true;
}
return admin.auth().setCustomUserClaims(userId, claim);
});
}
service firebase.storage {
match /b/{bucket}/o {
match /groups/{groupId} {
match /{path=**} {
allow read, write: if request.auth!=null
&& request.auth.token[groupId] == true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment