Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set firebase rules and updated pages for access checks #17

Open
wants to merge 1 commit into
base: 8-feature/push-notification
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
match /tokens/{userId} {
allow write: if request.auth.uid == userId;
allow read: if false;
}
match /products/{product} {
allow read: if true;
allow write: if exists(/databases/$(database)/documents/admins/$(request.auth.uid));
}
match /admins/{userId} {
allow get: if request.auth.uid != null;
allow list: if false;
allow write: if false;
}
match /orders/{orderId} {
allow read: if request.auth.uid == resource.data.uid || exists(/databases/$(database)/documents/admins/$(request.auth.uid));
allow create: if request.auth.uid != null;
allow update: if exists(/databases/$(database)/documents/admins/$(request.auth.uid));
allow delete: if false;
}
}
}
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h4>AWESOME SALE</h4>
<!-- Start Load More -->
<div class="center-align">
<a class="waves-effect waves-light btn-large teal darken-2 hide" id="see-more"><i class="material-icons left">view_headline</i>See More</a>
<a class="waves-effect waves-light btn-large teal darken-2" href="/add-product.html"><i class="material-icons left">add_circle</i>Add Product</a>
<a class="waves-effect waves-light btn-large teal darken-2 hide" href="/add-product.html" id="add-product"><i class="material-icons left">add_circle</i>Add Product</a>
</div>
<!-- End Load More -->
</div>
Expand Down
15 changes: 14 additions & 1 deletion public/js/add-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ function guid() {
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
}

$(window).on('auth', function(e, user) {
if (user) {
var adminsCollection = firebase.firestore().collection('admins');
adminsCollection.doc(user.uid).get().then(function(snapshot) {
if (!snapshot.exists) {
window.location = '/';
}
});
} else {
window.location = '/';
}
});
13 changes: 12 additions & 1 deletion public/js/browse-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ function browseProducts() {
}
}

$(document).ready(browseProducts);
$(document).ready(browseProducts);

$(window).on('auth', function(e, user) {
if (user) {
var adminsCollection = firebase.firestore().collection('admins');
adminsCollection.doc(user.uid).get().then(function(snapshot) {
if (snapshot.exists) {
$('#add-product').removeClass('hide');
}
});
}
});
2 changes: 1 addition & 1 deletion public/js/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function orders(user, isAdmin) {
'<h6>P ' + cost.toFixed(2) + ' for ' + order.quantity + ' items</h6>' +
'<p>' + order.firstName + ' ' + order.lastName +'</p>' +
'<p>' + order.address +'</p>';
if (isAdmin && order.status) {
if (order.status) {
template += '<p>' + order.status + '</p>'
}
template += '</div>';
Expand Down