How to prevent double join to the channel?

How to figure out that socket is already joined the channel? I need backend solution as I can’t trust client code.

Can you describe your issue a little more? The phoenix.js client prevents any channel instance from double joining by throwing an error. Likewise, the server will detect multiple channel joins against the same topic for an open connection, and close the existing one in such cases (with a logged warning). So you are already covered on the client and server, but perhaps you mean “double join” in a different way, such as preventing multiple tabs/browsers/devices from joining while another is joined? If you can provide more details on your usecase then I can say more.


Hey Chris!

Yes, I’ve meant double tabs or different browsers under one user.

Can you describe your usecase?

You can easily detect it via presence for example, if more than one entry then disconnect, however…

XY Problem. Disallowing more than one tab is bad for user experience in 99.99…% of cases, so more specifically ‘what’ are you trying to accomplish (not ‘how’)? :slight_smile:


100% agreed.

In my daily job, I am forced to use the software which does something like this, but not as strict as you want to do - it just asks if to override the session I started from the different browser. Nigthmare, when something goes wrong, I need to wait for all the sessions to timeout.

1 Like

Perhaps he’s trying to prevent paid account sharing. Just a guess.

Then add a rate limit or something, don’t block multiple windows, that is just evil design setup there…

Plus if it is the same session anyway, then what, are there multiple people on the same computer using it at the same time or something?

It could be for the prevention of multiple people from having multiple parallel sessions (e.g different devices) on the same account. Perhaps a banking app considered this for security purposes.

Bah, feels like our windows server policy which only allow two sessions at once…