Security & Rules API - Firebase
Security & Rules API - Firebase
Security&RulesAPIFirebase
FIREBASE
Types
.read
CODE EXAMPLE
.write
CODE EXAMPLE
.validate
CODE EXAMPLE
Used once a .write rule has granted access, to ensure that the data being
written conforms to a specific schema.
.indexOn
CODE EXAMPLE
https://www.firebase.com/docs/security/api/
1/9
15/3/2016
Security&RulesAPIFirebase
Variables
auth
CODE EXAMPLE
$location
now
null
CODE EXAMPLE
$location
that was
CODE EXAMPLE
root
CODE EXAMPLE
data
https://www.firebase.com/docs/security/api/
CODE EXAMPLE
2/9
15/3/2016
Security&RulesAPIFirebase
RuleDataSnapshot
newData
CODE EXAMPLE
RuleDataSnapshot
allowed.
RuleDataSnapshot
Methods
val()
CODE EXAMPLE
val()
child()
parent()
Gets a
) from this
CODE EXAMPLE
child(childPath)
Gets a
null
RuleDataSnapshot
CODE EXAMPLE
parent()
RuleDataSnapshot
https://www.firebase.com/docs/security/api/
15/3/2016
Security&RulesAPIFirebase
hasChild()
Returns
CODE EXAMPLE
hasChild(childPath)
true
hasChildren()
CODE EXAMPLE
hasChildren([children])
exists()
CODE EXAMPLE
exists()
Returns
true
getPriority()
if this
RuleDataSnapshot
Returns
isString()
CODE EXAMPLE
getPriority()
isNumber()
RuleDataSnapshot
CODE EXAMPLE
isNumber()
true
if this
isString()
https://www.firebase.com/docs/security/api/
RuleDataSnapshot
CODE EXAMPLE
4/9
15/3/2016
Security&RulesAPIFirebase
Returns
true
isBoolean()
Returns
if this
RuleDataSnapshot
CODE EXAMPLE
isBoolean()
true
if this
RuleDataSnapshot
String
Properties
length
CODE EXAMPLE
length
Methods
contains()
Returns
contains(substring)
true
beginsWith()
Returns
beginsWith(substring)
true
CODE EXAMPLE
CODE EXAMPLE
https://www.firebase.com/docs/security/api/
5/9
15/3/2016
Security&RulesAPIFirebase
endsWith()
Returns
replace()
endsWidth(substring)
true
CODE EXAMPLE
replace(substring, replacement)
CODE EXAMPLE
toLowerCase()
toLowerCase()
CODE EXAMPLE
toUpperCase()
toUpperCase()
CODE EXAMPLE
matches(regex)
Returns
true
matches(regex)
CODE EXAMPLE
https://www.firebase.com/docs/security/api/
6/9
15/3/2016
Security&RulesAPIFirebase
Operators
Methods
+ (add)
CODE EXAMPLE
- (negate or subtract)
CODE EXAMPLE
* (multiply)
CODE EXAMPLE
/ (divide)
CODE EXAMPLE
% (modulus)
CODE EXAMPLE
7/9
15/3/2016
Security&RulesAPIFirebase
=== (equals)
CODE EXAMPLE
Used to check if two variables in a rules expression have the same type
and value.
CODE EXAMPLE
&& (AND)
Evaluates to
CODE EXAMPLE
true
true
|| (OR)
Evaluates to
CODE EXAMPLE
true
! (NOT)
true
CODE EXAMPLE
https://www.firebase.com/docs/security/api/
8/9
15/3/2016
Security&RulesAPIFirebase
CODE EXAMPLE
CODE EXAMPLE
CODE EXAMPLE
CODE EXAMPLE
? (ternary operator)
CODE EXAMPLE
https://www.firebase.com/docs/security/api/
9/9