I use RedisAuthRepository as user auth repository in my .NET Core 2.0 app (ServiceStack 5.0.3), but I couldn’t read already stored UserAuth objects from my Redis db with GetUserAuthByUserName(UserName) the result is always null?
Any queries in Redis requires looking up an Index, for the UserName it tries looking it up from the hash:UserAuth:UserName>UserId index which is stored in a hash that’s maintained when users are added in the Repositories CreateUserAuth() or UpdateUserAuth() APIs. So I’d first check to make sure the UserName/UserId mapping exists in the hash:UserAuth:UserName>UserId hash.
I’m not able to repro this error which is working as expected. I’ve distilled it into the smallest example with minimal deps below.
One issue with your example is that you shouldn’t manually populate the PasswordHash/Salt as they are automatically populated by CreateUserAuth(). Also note that from v5.0.0 ServiceStack uses ASP.NET Identity v3’s PBKDF2 Password Hashing implementation instead of SaltedHash.
Otherwise this example works in both .NET Framework and .NET Core:
using (new BasicAppHost().Init())
{
var redisManager = new RedisManagerPool(redisHost);
var userRep = new RedisAuthRepository(redisManager);
var user = new UserAuth
{
DisplayName = "ssePosFeed-DisplayName",
Email = "ssePosFeed@if.com",
UserName = "ssePosFeed",
FirstName = "ssePosFeed-FirstName",
LastName = "ssePosFeed-LastName",
Roles = new List<string> { "SSEPosFeed" },
Permissions = new List<string> { "GetPosFeed" }
};
// Create user
userRep.CreateUserAuth(user, "blabla");
//userExist is always null
var userExist = userRep.GetUserAuthByUserName(user.UserName);
userExist.PrintDump();
}
thank you I found out the problem the __type was missed in the redis stored object…if I commented the line:
//JsConfig.ExcludeTypeInfo = true;
it run’s but is there another solution because if my MessageObject contains a property of type JsonObject so I won’t return the __type field therefore I have disabled it with JsConfig.ExcludeTypeInfo = true?
Excluding the TypeInfo is going to break deserializing anything that requires the __type info property (e.g. Auth Repos), which is only emitted when it’s needed.
See the docs on Customizing JSON for alt options for customizing JSON responses.