Refactored the huge and ugly auth.js service