refactored login.js file