refactoring authentication controller