What is the recommended approach to prevent the same user from authenticating on multiple devices?
What I would like to do is, when a user tries to connect to Nakama, I would like to disable the reconnect logic and disconnect him from all the connected devices with a meaningful message, for example:
A new device is connected using your account, logging out from this device
You have a configuration labeled session.single_socket, but this won’t serve my purpose since the client won’t get the reason why the user is suddenly disconnected from this device.
If possible please, let me know the possible Nakama Lua runtime to be used to solve this issue.
I’ve added a register_req_after hook, but I am not sure if it’s a reliable way to achieve the goal.
function after_match_join(context, payload)
local count = nk.stream_count({mode = 0, subject = context.user_id})
if (count >= 2) then
nk.logger_info("User is trying to join a match from another device: ".. context.user_id)
nk.notification_send(context.user_id, "A new user trying to join a match to this account", {}, 4)
end
end
- Nakama: Nakama: 3.8.0
- Server Framework Runtime language: Lua
- Unity SDK: 2.8.1