IO-3166-Global-Notifications-Part-2 - Checkpoint
This commit is contained in:
@@ -14,12 +14,15 @@ const redisSocketEvents = ({
|
||||
// Socket Auth Middleware
|
||||
const authMiddleware = async (socket, next) => {
|
||||
const { token, bodyshopId } = socket.handshake.auth;
|
||||
|
||||
if (!token) {
|
||||
return next(new Error("Authentication error - no authorization token."));
|
||||
}
|
||||
|
||||
if (!bodyshopId) {
|
||||
return next(new Error("Authentication error - no bodyshopId provided."));
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await admin.auth().verifyIdToken(token);
|
||||
socket.user = user;
|
||||
|
||||
36
server/web-sockets/updateBodyshopCache.js
Normal file
36
server/web-sockets/updateBodyshopCache.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Update or invalidate bodyshop cache
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const updateBodyshopCache = async (req, res) => {
|
||||
const {
|
||||
sessionUtils: { updateOrInvalidateBodyshopFromRedis },
|
||||
logger
|
||||
} = req;
|
||||
|
||||
const { event } = req.body;
|
||||
const { new: newData } = event.data;
|
||||
|
||||
try {
|
||||
if (newData && newData.id) {
|
||||
// Update cache with the full new data object
|
||||
await updateOrInvalidateBodyshopFromRedis(newData.id, newData);
|
||||
logger.logger.debug("Bodyshop cache updated successfully.");
|
||||
} else {
|
||||
// Invalidate cache if no valid data provided
|
||||
await updateOrInvalidateBodyshopFromRedis(newData.id);
|
||||
logger.logger.debug("Bodyshop cache invalidated successfully.");
|
||||
}
|
||||
res.status(200).json({ success: true });
|
||||
} catch (error) {
|
||||
logger.log("bodyshop-cache-update-error", "ERROR", "api", "redis", {
|
||||
message: error?.message,
|
||||
stack: error?.stack
|
||||
});
|
||||
res.status(500).json({ success: false, error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = updateBodyshopCache;
|
||||
Reference in New Issue
Block a user