Reorganize authentication flow