Fixing a bug where all users would be logged out unexpectedly

- Moved attach from post to pre so that the identity is still available.
- Added condition to removing the sessions from the db so that only the current user's sessions are removed, not all users.