Skip to content

Commit 044f044

Browse files
committed
fix(handshake): store user data in socket.data for online-users widget
The handshake middleware stored admin user as socket.adminUser but the getOnlineUsers endpoint reads socket.data.user (Socket.IO's standard data property). Changed to socket.data.user so the Who's Online widget shows actual user names instead of "Anonymous".
1 parent bf0e129 commit 044f044

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

dist/server/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ async function handshake(socket, next) {
7979
const ctx = await strategyService[strategyType].authenticate(auth);
8080
room = strategyService[strategyType].getRoomName(ctx);
8181
if (strategyType === "admin") {
82-
socket.adminUser = ctx;
82+
socket.data.user = ctx;
83+
} else if (strategyType === "role" && ctx) {
84+
socket.data.user = { role: ctx };
8385
}
8486
} else if (strapi.plugin("users-permissions")) {
8587
const role = await strapi.documents("plugin::users-permissions.role").findFirst({

dist/server/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ async function handshake(socket, next) {
4545
const ctx = await strategyService[strategyType].authenticate(auth);
4646
room = strategyService[strategyType].getRoomName(ctx);
4747
if (strategyType === "admin") {
48-
socket.adminUser = ctx;
48+
socket.data.user = ctx;
49+
} else if (strategyType === "role" && ctx) {
50+
socket.data.user = { role: ctx };
4951
}
5052
} else if (strapi.plugin("users-permissions")) {
5153
const role = await strapi.documents("plugin::users-permissions.role").findFirst({

server/src/middleware/handshake.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ async function handshake(socket, next) {
3333
room = strategyService[strategyType].getRoomName(ctx);
3434

3535
if (strategyType === 'admin') {
36-
socket.adminUser = ctx;
36+
socket.data.user = ctx;
37+
} else if (strategyType === 'role' && ctx) {
38+
socket.data.user = { role: ctx };
3739
}
3840
} else if (strapi.plugin('users-permissions')) {
3941
const role = await strapi.documents('plugin::users-permissions.role').findFirst({

0 commit comments

Comments
 (0)