Skip to content

Commit 1169045

Browse files
committed
initial commit
0 parents  commit 1169045

12 files changed

+6801
-0
lines changed

.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "angularfirebase-267db"
4+
}
5+
}

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
9+
# Firebase cache
10+
.firebase/
11+
12+
# Firebase config
13+
14+
# Uncomment this if you'd like others to create their own Firebase project.
15+
# For a team working on the same Firebase project(s), it is recommended to leave
16+
# it commented so all members can deploy to the same project(s) in .firebaserc.
17+
# .firebaserc
18+
19+
# Runtime data
20+
pids
21+
*.pid
22+
*.seed
23+
*.pid.lock
24+
25+
# Directory for instrumented libs generated by jscoverage/JSCover
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
coverage
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (http://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
node_modules/
48+
49+
# Optional npm cache directory
50+
.npm
51+
52+
# Optional eslint cache
53+
.eslintcache
54+
55+
# Optional REPL history
56+
.node_repl_history
57+
58+
# Output of 'npm pack'
59+
*.tgz
60+
61+
# Yarn Integrity file
62+
.yarn-integrity
63+
64+
# dotenv environment variables file
65+
.env

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Episode 147 - Testing Firestore Rules with the Emulator
2+
3+
Learn test your Firebase security rules using the new Firestore emulator.

firebase.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"firestore": {
3+
"rules": "firestore.rules",
4+
"indexes": "firestore.indexes.json"
5+
}
6+
}

firestore.indexes.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"indexes": []
3+
}

firestore.rules

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
service cloud.firestore {
2+
match /databases/{database}/documents {
3+
4+
// Secure by default
5+
match /{document=**} {
6+
allow read: if false;
7+
allow write: if false;
8+
}
9+
10+
// Unsecured Rules
11+
match /posts/{docId} {
12+
allow read, write;
13+
}
14+
15+
// Secured to authenticated users
16+
match /comments/{docId} {
17+
allow read: if request.auth.uid != null;
18+
allow write: if request.auth.uid == request.resource.data.userId;
19+
}
20+
21+
// Role-based authorization
22+
function getUserData() {
23+
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data
24+
}
25+
26+
match /projects/{docId} {
27+
allow read, write: if getUserData().roles['admin'] == true || resource.data.members.hasAny([request.auth.uid])
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)