Refactor the login javascript so it can be used by both the navbar login form and the record form when sessions are lost