Question

is there a way to manage users with ServiceStack?

I've only found the IUserAuthRepository interface that has some methods to get a user by name, email and id. But how to get a list of users (with filters & co).

Thanks.

Was it helpful?

Solution

I think some of this depends on where and how you're storing you data.

If you are storing the data in a SQL database there should be 3 tables holding user data User, UserAuth, UserOAuthProvider. Most of the user data you want will probably be within the UserAuth table. At least, this is the table that seems to be mostly referenced with the 'OrmLiteAuthRepository'. To return a list of users (List<UserAuth>) using OrmLite you could do

using (IDbConnection con = DbConnectionFactory.OpenDbConnection())
{
    var users = con.Select<UserAuth>();
}

Or use whatever your preferred way of accessing is.

If you are not using a SQL database it will vary. I think you can do something like below for Redis. I don't think the 'configuration' is a straight forward but it looks like you start by accessing a Hash. There are two options for the 'HashId'. Use 'hash:UserAuth:Email>UserId' when email address is a key and 'hash:UserAuth:UserName>UserId' when username is a key. FYI, these values could change, but I'm not aware of a way to access them via ServiceStack code.

using (IRedisClient client = RedisClientManager.GetClient())
{
    var userskeys = client.GetHashKeys("hash:UserAuth:Email>UserId").ToList();
    var users =  userskeys.Select(k => client.As<UserAuth>().GetById(k)).ToList();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top