Some code for login flow handling