In an MVC app UserId of current user can be obtained using WebSecurity.UserId, but if I do that during the login action it will return -1. The reason for that is explained here and here. Basically the authorization cookie is set during login, but the framework will have access to it no sooner than during the next request. I can somewhat get around not having UserId in login action by pulling the user from database based on his\hers name.
However I can't do the same when it comes to external login as I don't have easy access to user's name. For various reasons I need to run two functions that take UserId as input and I need to do so right after login using external account. I'd prefer if I could somehow do so within the external login action. So, is there any way to get UserId of the user who just logged in without reloading page (redirecting somewhere else)?
I have also this problem which I could probably solve if I could get my hands on UserId of the currently logged user (even if his authorization cookie was just set during current request). Because of this, I was looking for some more general solution rather than just finding ways to extract user's email from google and facebook callback data during the external login.