Skip to content

Instantly share code, notes, and snippets.

View AndroidBullOfficial's full-sized avatar

Waqas Younis AndroidBullOfficial

View GitHub Profile
// Validates user is moderator from different database location
{
“rules”: {
“posts”: {
“$uid”: {
“.write”: “root.child(‘users’).child(‘moderator’).val() === true”
}
}
}
}
// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
// Only authenticated users from a particular domain (example.com) can access/write data
{
“rules”: {
“.read”: “auth.token.email.endsWith(‘@example.com’)”,
“.write”: “auth.token.email.endsWith(‘@example.com’)”
}
}
// Only authenticated users can access/write data
{
“rules”: {
“.read”: “auth != null”,
“.write”: “auth != null”
}
}
// Full security
{
“rules”: {
“.read”: false,
“.write”: false
}
}
// No Security
{
“rules”: {
“.read”: true,
“.write”: true
}
}
// Prevents Delete or Update
{
“rules”: {
“posts”: {
“$uid”: {
“.write”: “!data.exists()”
}
}
}
}
// Prevents only Delete
{
“rules”: {
“posts”: {
“$uid”: {
“.write”: “newData.exists()”
}
}
}
}
// Prevents Create and Delete
{
“rules”: {
“posts”: {
“$uid”: {
“.write”: “data.exists() && newData.exists()”
}
}
}
}
// Allow reads if the group ID in your token matches the file metadata's `owner` property
// Allow writes if the group ID is in the user's custom token
match /files/{groupId}/{fileName} {
allow read: if resource.metadata.owner == request.auth.token.groupId;
allow write: if request.auth.token.groupId == groupId;
}