Skip to content
Discussion options

You must be logged in to vote

You can prevent race conditions at the database level - if two requests try to create active sessions simultaneously, one will fail.
something like this:-

CREATE UNIQUE INDEX idx_one_active_session_per_user 
ON user_sessions (user_id) 
WHERE status = 'active';

and maybe you can consider
Transaction for session switches:

await session.db.transaction((tx) async {
  await endSession(currentSessionId);
  return await createSession(userId, newRoomId);
});

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@nthenyaserah
Comment options

Answer selected by nthenyaserah
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants