You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| helpers |`["authUserEmail", "authUserEmailIsVerified", "authUserUid", "existingData", "hasAmtOfWriteFields", "incomingData", "isAuthenticated"]`| array(strings) \| boolean | used to add helper functions to the output, this can be `true` to include all helper functions or `false` to include non of the helper functions or an array of the [function names](#helper-functions)|
91
+
| custom_helpers_folder |`null`|`null`\| string | path to user defined helper functions |
92
+
| rules_version |`"1"`|`"1"`\|`"2"`\|`1`\|`2`| which version is the rules written in |
93
+
| rules_folder |`"rules"`| string | folder where the rule fragments can be found |
94
+
| rules_output |`"firestore.rules"`| string | name of the file to output to |
95
+
| use_firebase_config |`false`| boolean | use the firebase config file `firebase.json` to get the rules output file name and location |
57
96
58
-
Firestore-Rulez can be configured by adding a rulez.config.js file to the `./rules` folder. At this point, the file can contain following settings:
97
+
## Default Configuration File
59
98
60
99
```js
61
100
module.exports= {
62
-
// Enables helper functions as specified below
63
-
helpers:false,
64
-
rules_version:'1'
65
-
}
101
+
helpers: [
102
+
"authUserEmail",
103
+
"authUserEmailIsVerified",
104
+
"authUserUid",
105
+
"existingData",
106
+
"hasAmtOfWriteFields",
107
+
"incomingData",
108
+
"isAuthenticated",
109
+
],
110
+
custom_helpers_folder:null,
111
+
rules_version:1,
112
+
rules_folder:"rules",
113
+
rules_output:"firestore.rules",
114
+
use_firebase_config:false,
115
+
};
66
116
```
67
117
68
118
# Helper Functions
69
119
70
-
The following helper functions are present, if the helpers option is enabled:
120
+
The following helper functions are present, if the helpers option is enabled or the function is included:
121
+
| name | description |
122
+
| --- | ---|
123
+
| isAuthenticated | Checks if user is authenticated |
124
+
| authUserUid | Returns Current Auth User's Uid |
125
+
| authUserEmail | Returns Current Auth User's Email |
126
+
| authUserEmailIsVerified | Returns wether Current Auth User's Email is verified |
127
+
| existingData | Returns the existing data |
128
+
| incomingData | Returns the incoming data |
129
+
| hasAmtOfWriteFields | Checks if the request has X write fields |
130
+
131
+
Use the name of the functionin the rules files and in the configuration file to enable them in the configuration or set the helpers function to true to include them all.
132
+
133
+
## isAuthenticated
71
134
72
135
```js
73
136
// Checks if user is authenticated
74
137
functionisAuthenticated() {
75
-
returnrequest.auth!=null
138
+
returnrequest.auth!=null;
76
139
}
140
+
```
141
+
142
+
## authUserUid
77
143
144
+
```js
78
145
// Returns Current Auth User's Uid
79
146
functionauthUserUid() {
80
-
returnrequest.auth.uid
147
+
returnrequest.auth.uid;
81
148
}
149
+
```
150
+
151
+
## authUserEmail
82
152
153
+
```js
83
154
// Returns Current Auth User's Email
84
155
functionauthUserEmail() {
85
-
returnrequest.auth.token.email
156
+
returnrequest.auth.token.email;
86
157
}
158
+
```
159
+
160
+
## authUserEmailIsVerified
87
161
162
+
```js
88
163
// Returns wether Current Auth User's Email is verified
89
164
functionauthUserEmailIsVerified() {
90
-
returnrequest.auth.token.email_verified
165
+
returnrequest.auth.token.email_verified;
91
166
}
167
+
```
168
+
169
+
## existingData
92
170
171
+
```js
93
172
// Returns the existing data
94
173
functionexistingData() {
95
-
returnresource.data
174
+
returnresource.data;
96
175
}
176
+
```
97
177
178
+
## incomingData
179
+
180
+
```js
98
181
// Returns the incoming data
99
182
functionincomingData() {
100
-
returnrequest.resource.data
183
+
returnrequest.resource.data;
101
184
}
185
+
```
102
186
187
+
## hasAmtOfWriteFields
188
+
189
+
```js
103
190
// Checks if the request has X write fields
104
191
functionhasAmtOfWriteFields(size) {
105
-
returnrequest.writeFields.size() == size
192
+
returnrequest.writeFields.size() == size;
106
193
}
107
194
```
108
195
109
-
###Credits
196
+
# Credits
110
197
111
198
Thanks to [OneLunch Man](https://stackoverflow.com/users/10747134/onelunch-man) for inspiring me to build this module on Stack Overflow.
0 commit comments