diff --git a/app/components/NotificationHandler.js b/app/components/NotificationHandler.js index 38ad3b4..c4f5423 100644 --- a/app/components/NotificationHandler.js +++ b/app/components/NotificationHandler.js @@ -88,10 +88,8 @@ export default function NotificationHandler() { async function handleEnable() { setShowPrompt(false); - // This MUST be synchronous from a user gesture const permission = await Notification.requestPermission(); - if (permission === "granted") { await setupFCM(); } diff --git a/app/hooks/useAuth.js b/app/hooks/useAuth.js index f662422..2f19cdc 100644 --- a/app/hooks/useAuth.js +++ b/app/hooks/useAuth.js @@ -9,7 +9,7 @@ export default function useAuth() { name: authUser?.name ?? "Not found", email: authUser?.email ?? "Not found", isOwner: role?.includes("Owner"), - isAgent: role?.includes("RealEstateAgent",""), + isAgent: role?.includes("RealEstateAgent"), isCustomer: role?.includes("Customer"), role: role, isGuest: !authUser, diff --git a/app/services/AuthService.js b/app/services/AuthService.js index 5a0220e..fd73018 100644 --- a/app/services/AuthService.js +++ b/app/services/AuthService.js @@ -66,9 +66,7 @@ const AuthService = Object.freeze({ */ getCachedUser() { const user = Cookies.get(USER_KEY); - if (!user) return null; - try { return JSON.parse(user); } catch { diff --git a/public/firebase-messaging-sw.js b/public/firebase-messaging-sw.js index 910512d..cf0ea4d 100644 --- a/public/firebase-messaging-sw.js +++ b/public/firebase-messaging-sw.js @@ -31,10 +31,25 @@ messaging.onBackgroundMessage((payload) => { self.registration.showNotification(title, options); }); +function mapNotificationUrl(url) { + if (!url) return "/"; + if (url.startsWith("/SaleProperty/")) { + return url.replace("/SaleProperty/", "/owner/properties/"); + } + if (url.startsWith("/reservations/")) { + return url.replace("/reservations/", "/reservations/"); + } + if (url === "/" || url === "/home") { + return "/"; + } + return url; +} + // Handle notification click //اذا ضغطنا ع الاشعار شو بصير self.addEventListener("notificationclick", (event) => { event.notification.close(); - const url = event.notification.data?.url || "/"; + const notificationUrl = event.notification.data?.url || "/"; + const url = mapNotificationUrl(notificationUrl); event.waitUntil(clients.openWindow(url)); });