refactores authentication code and only showing login page first time user logs
refactored auth code