Our current app uses HTTP sessions and we'd like to replace that with JWT.
The setup allows only a single session per user. This means:
- User signs in at Device 1
- User is logged in at Device 1 (new Session created)
- User signs in at Device 2
- User is logged in at Device 2 (new Session created)
- User is not logged in at Device 1 (Session got destroyed)
This works because there's a server-side relation between session id and user id.
Using JWT I could imagine to have some counter inside the user database, which gets increased with every login, i.e.:
- User signs in at Device 1
- JWT tokens signature contains counter+1 (and save new counter to database)
- User signs in at Device 2
- JWT's signature contains counter+1 and it gets increased and saved to db.
Now with every request I have to check if the incoming signature is correct for the current counter value.
This somehow makes it stateful. :(
But ... one of JWT's benefits is, that there's no need to access any database or session store for validating the token.
Is there some other solution for preventing concurrent logins? Maybe something that works without database access and keeps it stateless?