I've implemented a chat feature using socket.io and nodejs. But now I want to implement a role based chat application. For example, if someone wants to communicate with someone who is in a higher position, first needs to send a request. I've implemented a chat request system(similar to friend request). But I dont know how to make it role-based. Can accesscontrol package be helpful in this case?
I've added a role property into the user model. I wanted to create a middleware to check what role has the user and to whom it wants to send the message. if its allowed it can continue with the 'chat', but if its not allowed I want it to redirect it to the request endpoint. I wanted to know if this logic is ok. If not, what could I do better.
EDIT: This solution with the middleware it seems to work :). If you have any better idea please answer my question
I don't have enough information to know exactly your case but it doesn't sound like you need access control. Here's my suggestion for you:
when they need to ask for request you would open a chat with the receiver but set in your database a special setting on the chat model: (access=false)
when the receiver goes in the app, they have a special section for chats filtered with the option (access=false), when they approve the chat, you change the setting and enable the chat to go back into the main queue and display messages