The only way I could accomplish this, and I’m sure is not the best solution was:
in the IUserAuthRepository.CreateUserAuth call, assign the first company ID (System Company)
when authenticate for the first time, under AuthUserSession.TryAuthenticate I see if the Email address provided (as username) exists in the UserAuth table with the System Company Id and if yes, then I update it with the correct one (passed by custom header).
It’s not elegant, but it does work (unless the same usermail is created multiple times without never authenticate
I’m not overly familiar with NHibernate myself, but once the authProvider.CreateUserAuth function has been called, the UserAuth should be persisted.
This would follow behaviour (as far as I understand) for the other implementations of the IAuthProvider interface. Eg,
Another way to have custom logic on registration would be to register your own IAuthEvents class and override OnRegistered method. This is fired after session.OnRegistered and has access to the Request, session and RegisterService instance. You can resolve your IUserAuthRepository from the registration service instance and update the user.
Is this the response from a successful registration? Can you provide more info on when this happens or a simple project reproducing the problem?
I’m not really experienced with nHibernate, but reading common problems it seems that a lot of the control of persistence is put back onto the consuming application, control over FlushMode and use of ‘2nd level cache’ seem like points that might be causing problems/confusion.
Happy to try and help though. Are you using FluentNHibernate.Cfg? Would you be able to provide your config code? Specifically how you are constructing the ISessionFactory?
In the OnRegistered event hook, could you call session.Transaction.Commit()? Again, I’m not sure what is considered 'best practice" in regards to NHibernate but my guess would be configuration or maybe (as is suggested here http://stackoverflow.com/questions/478827/nhibernate-update-not-working) an exception is being ignored somewhere that might be causing you to get null response from the registration call.