Persisting Roles to Cache when UseDistinctRoleTables = true

Hi I used the normal mix to add Configure.AppHost, Configure.Auth, Configure.AuthRepository, Configure.Cors, Configure.Db and Configure.Redis.

When UseDistinctRoleTables is false, the Roles are cached in Redis, but the moment that UseDistinctRoles is true, Redis just caches part of the session excluding the roles which is confusing.

The documentation is not clear that just changing UseDistinctTables from true to false will have such an adverse effect. When calling auth and logging in, the role comes back from the distinct table in the response, but the session on redis does not contain the role.

I love servicestack and have been using it for years, but this is the first time using UseDistinctRoleTables.

This should be made very clear in the documentation. Please let me know how I can persist all the relevant user tables…UserAuthDetails,UserAuthRole and UserAuth to redis when using UseDistinctRoles.

Thanks

The built-in behavior of UseDistinctRoleTables in OrmLiteAuthRepository is for the master authority of a Users Roles to be managed by the RDBMS which it looks up dynamically when validating role.

When you use UseDistinctRoleTables the roles are no longer blobbed on the UserAuth table which is what populates the Users Session and because OrmLiteAuthRepository implements IManageRoles/Async it tells ServiceStack to always use the repository to check for roles.

You can override the behavior of how it checks for Roles by overriding the GetRoles/Async APIs in your custom AuthUserSession to not use the Auth Repo when the registered AuthRepository implements IManageRoles/Async:

But then you’d need to make sure to populate the Roles on the User Session when saving it to the cache which you can do by overriding OnSaveSessionAsync in your AppHost.