Refactored authentication controller