Admin can disable or suspend user's entrance.
We can check "is user disabled" in "user login". ("Checking Db for each request" is not good option)
So we want to remove user's session when admin disables it's account.
How can we achieve it?
Admin can disable or suspend user's entrance.
We can check "is user disabled" in "user login". ("Checking Db for each request" is not good option)
So we want to remove user's session when admin disables it's account.
How can we achieve it?
If you know or have kept the
sessionId
you can remove a session from the cache with:But ServiceStack doesn't keep a map of all User's Session ids itself. One way to avoid DB lookups on each request is when disabling the account keep a record of the disabled User Ids which you can later validate in a global Request Filter to ensure the user isn't locked.
Best way to store the locked user ids is in the cache that way the visibility and lifetime of the locked user ids is in the same cache storing the sessions. You can use a custom cache key to record locked user ids, e.g:
This will remove the locked users sessions the next time they try to access ServiceStack, forcing them to login again at which point they will notice they've been locked out.
A new RemoveSession API was added in this commit which makes this a little nicer (from v4.0.34+):