Refactor authentication. No code duplication in controllers