← Retour à la marketplaceVoir les projets →
🔔
Notifications
Système de notifications in-app en temps réel avec préférences utilisateur.
CommunicationSimple~3 joursv1.1.0
Module de notifications en temps réel via Server-Sent Events, avec centre de notifications, marquage lu/non-lu, préférences par canal (in-app, email) et types de notifications paramétrables.
notificationsrealtimessealertsinbox
Dépendances requises :
📋 Schéma Prisma
// === Module Notifications ===
enum NotificationType {
INFO
SUCCESS
WARNING
ERROR
}
model Notification {
id String @id @default(cuid())
userId String
type NotificationType @default(INFO)
title String
body String?
link String?
readAt DateTime?
createdAt DateTime @default(now())
@@index([userId, readAt])
@@map("notifications")
}
model NotificationPreference {
id String @id @default(cuid())
userId String @unique
inApp Boolean @default(true)
email Boolean @default(true)
categories Json @default("{}")
@@map("notification_preferences")
}🔌 Endpoints API
## API Notifications GET /api/notifications # Liste (non lues en premier) POST /api/notifications/:id/read # Marquer comme lu POST /api/notifications/read-all # Tout marquer comme lu DELETE /api/notifications/:id # Supprimer GET /api/notifications/stream # SSE stream des nouvelles notifications GET /api/notifications/preferences # Préférences PUT /api/notifications/preferences # Mettre à jour # Interne (pour les autres modules) POST /api/internal/notify # Créer une notification programmatiquement
🛠️ Guide d'implémentation
## Implémentation Notifications ### Étape 1 — Modèles et service Créer src/lib/notifications/service.ts avec une fonction createNotification() utilisable par tous les modules. ### Étape 2 — SSE Stream Route GET /api/notifications/stream : - Authentifiée via cookie/header - Maintient connexion ouverte - Envoie un ping toutes les 30s - Push des nouvelles notifications ### Étape 3 — Client Hook React useNotifications() : - Connexion SSE - Mise à jour du compteur non-lu - Toast automatique sur nouvelle notification
Prêt à installer ce module ?
Ajoutez-le à un projet existant depuis la page modules du projet.