Skip to content

Commit

Permalink
FIxed website not working on private windows due to notification prob…
Browse files Browse the repository at this point in the history
…lems
  • Loading branch information
porfanid committed Jan 5, 2025
1 parent 1a7a189 commit 48209fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions .config/firebase/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ service cloud.firestore {
anyRoleIn(database,request.auth.uid, ['admin']);
}
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Allow read if authenticated and the user is accessing their own data
allow read: if request.auth != null && request.auth.uid == userId;

// Allow write only if:
// 1. User is updating their own data but not the 'role' field, or
// 2. User has an admin role (in the list of roles), or
// 3. User is updating their own role and is an admin.
allow write: if request.auth != null && request.auth.uid == userId && (
// Case 1: Updating their own data, excluding 'role' field
!(request.resource.data.keys().hasAny(['role']) && request.resource.data.role != resource.data.role)
// Case 2: Admin role check
|| anyRoleIn(database, request.auth.uid, ['admin'])
);
}
match /chiefs/{document=**} {
allow read: if true; // Public read access
allow write: if request.auth != null &&
Expand Down
7 changes: 5 additions & 2 deletions src/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const auth = getAuth(app);
const analytics = getAnalytics(app);
const db = getFirestore(app);
const functions = getFunctions(app);
const messaging = getMessaging(app);
let messaging = null

/**
if (import.meta.env.MODE === 'development') {
Expand All @@ -29,7 +29,10 @@ if (import.meta.env.MODE === 'development') {
}
**/

if ("serviceWorker" in navigator) {
if (navigator.serviceWorker) {

messaging = getMessaging(app);

navigator.serviceWorker.register("/firebase-messaging-sw.js")
.then((registration) => {
console.log("Service Worker registered with scope:", registration.scope);
Expand Down

0 comments on commit 48209fe

Please sign in to comment.