Handle login and cookies properly