Yes, it always returns what I assume is a guest account. It certainly isn't returning the logged in user details.
I suspect the work context won't be updated with the logged in customer until the login action issues the redirect to the next page and the authentication cookie is read as part of that request.
If you want to execute some code on login you might be better off creating a plugin that consumes the CustomerLoggedInEvent that is published after a successful login. See this post for more on how to consume an event from a plugin by implementing the IConsumer interface. The advantage of doing it this way is that the logged in customer object is going to be passed to the HandleEvent method of the event consumer.
Yes, it always returns what I assume is a guest account. It certainly isn't returning the logged in user details. I suspect the work context won't be updated with the logged in customer until the login action issues the redirect to the next page and the authentication cookie is read as part of that request.
If you want to execute some code on login you might be better off creating a plugin that consumes the CustomerLoggedInEvent that is published after a successful login. See this post for more on how to consume an event from a plugin by implementing the IConsumer interface. The advantage of doing it this way is that the logged in customer object is going to be passed to the HandleEvent method of the event consumer.
Thank you. I'll look at that now and post back my findings.