refactoring and testing auth feature