I have an application with an authentication and list management system. The application uses React in front-end and Express/Mongo in back-end A user can add an item to another user's list that is stored in BDD in a list attached to a user.
I manage to get a notification to be sent to a specific user that a new object has been added to their collection, and get the notification.
socket.on("sendNotification", ({ senderName, receiverName, type }) => {
const receiver = getUser(receiverName);
io.to(receiver.socketId).emit("getNotification", {
senderName,
type,
});
});
useEffect(() => {
socket.on("getNotification", (data) => {
setNotifications((prev) => [...prev, data]);
});
}, [socket]);
But if the receiver user is not logged in, the notification is lost.
how to queue websocket events when a user is offline, and forward them to their next login?