feature/IO-3000-messaging-sockets-migrations2 -
- Fix Chat Icon logger error - Fix Socket Robustness - added additional wss status for error - Installed ant-design icons Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -46,18 +46,25 @@ const redisSocketEvents = ({
|
||||
|
||||
// Token Update Events
|
||||
const registerUpdateEvents = (socket) => {
|
||||
let latestTokenTimestamp = 0;
|
||||
|
||||
const updateToken = async (newToken) => {
|
||||
const currentTimestamp = Date.now();
|
||||
latestTokenTimestamp = currentTimestamp;
|
||||
|
||||
try {
|
||||
// noinspection UnnecessaryLocalVariableJS
|
||||
// Verify token with Firebase Admin SDK
|
||||
const user = await admin.auth().verifyIdToken(newToken, true);
|
||||
|
||||
// Skip outdated token validations
|
||||
if (currentTimestamp < latestTokenTimestamp) {
|
||||
createLogEvent(socket, "warn", "Outdated token validation skipped.");
|
||||
return;
|
||||
}
|
||||
|
||||
socket.user = user;
|
||||
|
||||
// If We ever want to persist user Data across workers
|
||||
// await setSessionData(socket.id, "user", user);
|
||||
|
||||
// Uncomment for further testing
|
||||
// createLogEvent(socket, "debug", "Token updated successfully");
|
||||
|
||||
createLogEvent(socket, "debug", `Token updated successfully for socket ID: ${socket.id}`);
|
||||
socket.emit("token-updated", { success: true });
|
||||
} catch (error) {
|
||||
if (error.code === "auth/id-token-expired") {
|
||||
@@ -66,14 +73,17 @@ const redisSocketEvents = ({
|
||||
success: false,
|
||||
error: "Stale token."
|
||||
});
|
||||
} else {
|
||||
createLogEvent(socket, "error", `Token update failed: ${error.message}`);
|
||||
socket.emit("token-updated", { success: false, error: error.message });
|
||||
// For any other errors, optionally disconnect the socket
|
||||
socket.disconnect();
|
||||
return; // Avoid disconnecting for expired tokens
|
||||
}
|
||||
|
||||
createLogEvent(socket, "error", `Token update failed for socket ID: ${socket.id}, Error: ${error.message}`);
|
||||
socket.emit("token-updated", { success: false, error: error.message });
|
||||
|
||||
// Optionally disconnect for invalid tokens or other errors
|
||||
socket.disconnect();
|
||||
}
|
||||
};
|
||||
|
||||
socket.on("update-token", updateToken);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user