refactor of login to make it asynchronous