Refactor to clean up auth.js