Custom authentication refactoring