diff --git a/src/app/dashboard/settings/account/page.tsx b/src/app/dashboard/settings/account/page.tsx
index d4bc6fe..2ab036c 100644
--- a/src/app/dashboard/settings/account/page.tsx
+++ b/src/app/dashboard/settings/account/page.tsx
@@ -222,6 +222,7 @@ export default function AccountSettingsPage() {
Get notified in your browser when you receive new messages and updates.
+ When you click Enable, your browser will show a permission prompt—choose Allow.
{pushLoading ? (
@@ -262,10 +263,11 @@ export default function AccountSettingsPage() {
type="button"
onClick={async () => {
setPushActionLoading(true)
- const ok = await subscribe()
+ setError("")
+ const result = await subscribe()
setPushActionLoading(false)
- if (!ok) {
- setError("Could not enable notifications. Check that the site has permission.")
+ if (!result.success) {
+ setError(result.error ?? "Could not enable notifications. Try again or check browser settings.")
}
}}
disabled={pushActionLoading}
diff --git a/src/app/supplier/settings/page.tsx b/src/app/supplier/settings/page.tsx
index bbaa313..8b942c2 100644
--- a/src/app/supplier/settings/page.tsx
+++ b/src/app/supplier/settings/page.tsx
@@ -232,6 +232,7 @@ export default function SupplierSettingsPage() {
Get notified in your browser when you receive new messages and updates.
+ When you click Enable, your browser will show a permission prompt—choose Allow.
{pushLoading ? (
@@ -272,9 +273,10 @@ export default function SupplierSettingsPage() {
type="button"
onClick={async () => {
setPushActionLoading(true)
- const ok = await subscribe()
+ setError("")
+ const result = await subscribe()
setPushActionLoading(false)
- if (!ok) setError("Could not enable notifications. Check that the site has permission.")
+ if (!result.success) setError(result.error ?? "Could not enable notifications. Try again or check browser settings.")
}}
disabled={pushActionLoading}
className="px-4 py-2.5 bg-indigo-500 text-white rounded-xl font-bold hover:bg-indigo-600 transition-colors flex items-center gap-2 disabled:opacity-50"
diff --git a/src/hooks/usePushNotifications.ts b/src/hooks/usePushNotifications.ts
index d26779b..2cbcf6b 100644
--- a/src/hooks/usePushNotifications.ts
+++ b/src/hooks/usePushNotifications.ts
@@ -57,10 +57,17 @@ export function usePushNotifications() {
checkSubscription()
}, [checkSubscription])
- const subscribe = async () => {
+ const subscribe = async (): Promise<{ success: boolean; error?: string }> => {
if (!VAPID_PUBLIC_KEY) {
console.error('VAPID public key not found')
- return false
+ return { success: false, error: 'Server configuration error. Please try again later or contact support.' }
+ }
+
+ if (Notification.permission === 'denied') {
+ return {
+ success: false,
+ error: 'Notifications are blocked. In your browser, click the lock icon in the address bar → Site settings → Notifications → set to Allow, then refresh this page.'
+ }
}
try {
@@ -79,12 +86,28 @@ export function usePushNotifications() {
if (response.ok) {
setIsSubscribed(true)
setPermission(Notification.permission)
- return true
+ return { success: true }
}
- return false
+
+ const data = await response.json().catch(() => ({}))
+ const msg = data?.message || (response.status === 401 ? 'Please log in again.' : 'Server error. Please try again later.')
+ return { success: false, error: msg }
} catch (error) {
console.error('Error subscribing to push notifications:', error)
- return false
+ const isPermissionDenied = error instanceof Error && (
+ error.name === 'NotAllowedError' ||
+ (error as DOMException).name === 'NotAllowedError'
+ )
+ if (isPermissionDenied) {
+ return {
+ success: false,
+ error: 'Notification permission was denied. To enable: click the lock icon in the address bar → Site settings → Notifications → Allow, then refresh.'
+ }
+ }
+ return {
+ success: false,
+ error: 'Could not enable notifications. Make sure the site is allowed to show notifications in your browser settings, then try again.'
+ }
}
}