AuthUserSession onLogout method alternatives

Hi ServiceStack team

in my SS selfhosted app I have extended the AuthUserSession class and added some properties

then I use the Session object method onLogout() to log to database when the session expires

all works fine but overriding the onLogout method has forced me to add dependency to my repository project

now I would like to share my custom class session between others SS selfhosted app
so I’m trying to move my custom class session to a package (ServiceModel) which has only interfaces and no dependencies from others projects of my solution like repository but I cannot

so I would like to know if there is another way to intercept the logout of a session?
or there is a better solution than to extend the SS session class?


Yeah you can use AuthEvents, either by registering it in the IOC or on the AuthFeature plugin by overriding the AuthEvents base class and implementing the Auth Events you want to handle, e.g:

public class MyAuthEvents : AuthEvents
    public override Task OnLogoutAsync(IRequest httpReq, IAuthSession session, 
        IServiceBase authService, CancellationToken token = default)

new AuthFeature(...)         {
    AuthEvents = { new MyAuthEvents() } 

great, it works like a charm

I love SS

thank you


1 Like