Refactored authentication to it's own factory