Skip to content

Add admin role check for messages from admin to socket connection #4

@VladimirTaytor

Description

@VladimirTaytor

Description

Inside socket connection handler we have event "message:send".
Clinet can send isAdmin flag inside data.sender, so server needs to validate this.

socket.on('message:send', function (data) {
      const message = {
        id: nanoid(),
        body: data.body,
        sender: data.sender,
        date: Date.now()
      };
      history.emit('save', message);
      chatRoom.emit('message:received', message)
    });

Implementation

Client sends a token on connection opening via handshake.
So the best way I think is to get this token and if isAdmin flag present, validate inside event callback the role of user, by geting user id from token and check role from DB.

Requires advanced level of coding skills.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions