Big refactor around the authentication flow.