Prepare get token form
Cherry pick
Cherry pick
Properly switch pages
Improve state handling
Update