Fixed a hanging login on incorrect credentials caused by race condition in the login function