refactor loggedin context