feature/IO-2776-cdk-fortellis - Cleanup + Auth Socket stuff
This commit is contained in:
@@ -36,9 +36,11 @@ const redisSocketEvents = ({
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await admin.auth().verifyIdToken(token);
|
||||
const user = await admin.auth().verifyIdToken(token, true);
|
||||
socket.user = user;
|
||||
socket.bodyshopId = bodyshopId;
|
||||
socket.data = socket.data || {};
|
||||
socket.data.authToken = token;
|
||||
await addUserSocketMapping(user.email, socket.id, bodyshopId);
|
||||
next();
|
||||
} catch (error) {
|
||||
@@ -69,6 +71,15 @@ const redisSocketEvents = ({
|
||||
}
|
||||
socket.user = user;
|
||||
socket.bodyshopId = bodyshopId;
|
||||
// 🔑 keep the live token in a mutable place used by downstream code
|
||||
socket.data = socket.data || {};
|
||||
socket.data.authToken = token;
|
||||
// also keep handshake in sync for any legacy reads
|
||||
if (socket.handshake?.auth) {
|
||||
socket.handshake.auth.token = token;
|
||||
socket.handshake.auth.bodyshopId = bodyshopId;
|
||||
}
|
||||
|
||||
await refreshUserSocketTTL(user.email, bodyshopId);
|
||||
socket.emit("token-updated", { success: true });
|
||||
} catch (error) {
|
||||
|
||||
@@ -9,7 +9,6 @@ const { PbsCalculateAllocationsAp, PbsExportAp } = require("../accounting/pbs/pb
|
||||
const { createLogEvent } = require("./createLogEvent");
|
||||
|
||||
function SetLegacyWebsocketHandlers(io) {
|
||||
|
||||
io.use(function (socket, next) {
|
||||
try {
|
||||
if (socket.handshake.auth.token) {
|
||||
@@ -53,6 +52,7 @@ function SetLegacyWebsocketHandlers(io) {
|
||||
socket.on("cdk-export-job", (jobid) => {
|
||||
CdkJobExport(socket, jobid);
|
||||
});
|
||||
|
||||
socket.on("cdk-selected-customer", (selectedCustomerId) => {
|
||||
createLogEvent(socket, "DEBUG", `User selected customer ID ${selectedCustomerId}`);
|
||||
socket.selectedCustomerId = selectedCustomerId;
|
||||
@@ -116,7 +116,6 @@ function SetLegacyWebsocketHandlers(io) {
|
||||
createLogEvent(socket, "DEBUG", `User disconnected.`);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
exports.SetLegacyWebsocketHandlers = SetLegacyWebsocketHandlers;
|
||||
exports.SetLegacyWebsocketHandlers = SetLegacyWebsocketHandlers;
|
||||
|
||||
Reference in New Issue
Block a user