Skip to content

[FE-28] Implement real-time notifications via Socket.io WebSocket connection #965

Description

@yusuftomilola

Overview

Notifications should arrive instantly without page refresh. This issue connects the frontend to the WebSocket notifications gateway (BE-55) using socket.io-client and pushes received events into the notification bell (FE-27) and as toast alerts.

Context

  • socket.io-client@4.8.3 is already installed in frontend/package.json
  • The existing frontend/hooks/useWebSocket.ts file provides a base — extend it for notifications
  • Backend WebSocket namespace: /notifications (from BE-55)
  • Authentication: pass { auth: { token: accessToken } } in the socket connection options

Acceptance Criteria

  • Create frontend/hooks/useNotificationSocket.ts — connects to NEXT_PUBLIC_API_URL on the /notifications namespace, passing the JWT from auth store as auth.token
  • On notification event: add the notification to the React Query useNotifications cache and increment the unread count badge
  • Show a toast (React Toastify) for each incoming notification: icon matches notification type, title from notification, dismiss after 5 seconds
  • Auto-reconnect on disconnect with exponential backoff
  • Disconnect the socket cleanly on logout (in the auth store logout() action)
  • Call useNotificationSocket() from the dashboard layout (frontend/app/(dashboard)/layout.tsx) so it runs for all authenticated pages

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions