| rules_version = '2'; |
| service cloud.firestore { |
| match /databases/{database}/documents { |
| |
| |
| |
| function isAuthenticated() { |
| return request.auth != null; |
| } |
|
|
| function isOwner(userId) { |
| return isAuthenticated() && request.auth.uid == userId; |
| } |
|
|
| function isValidUser(data) { |
| return data.keys().hasAll(['uid', 'email']) && |
| data.uid is string && |
| data.email is string && |
| (!('solvedQuestionIds' in data) || data.solvedQuestionIds is list); |
| } |
|
|
| |
| |
| |
| match /users/{userId} { |
| allow read: if isOwner(userId); |
| allow create: if isOwner(userId) && isValidUser(request.resource.data); |
| allow update: if isOwner(userId) && isValidUser(request.resource.data); |
| } |
| } |
| } |
|
|