AS move out duplicated code from login js