role to be assigned

I get this issue before. If we want to get the currentUser when the user is logged AFTER the page is loaded(maybe login with code), the currentUser returns no user is logged in. Can someone fix that?