refactoring login flow