Refactor authentication.js