diff --git a/lib/views/sign_up_password.dart b/lib/views/sign_up_password.dart index 34395a2..33b6efe 100644 --- a/lib/views/sign_up_password.dart +++ b/lib/views/sign_up_password.dart @@ -24,7 +24,6 @@ class _SignUpPasswordState extends State { String passwordError; bool loading = false; bool showPassword = true; - int currentStage = 0; void _signUpAction(BuildContext context, {Map auth}) async { MatrixState matrix = Matrix.of(context); @@ -43,11 +42,6 @@ class _SignUpPasswordState extends State { setState(() => loading = true); Future waitForLogin = matrix.client.onLoginStateChanged.stream.first; - if (auth == null) { - currentStage = 0; - } else { - currentStage++; - } await matrix.client.register( username: widget.username, password: passwordController.text, @@ -63,9 +57,16 @@ class _SignUpPasswordState extends State { .firstWhere((a) => !a.stages.contains("m.login.email.identity")) .stages; - if (stages[currentStage] == "m.login.dummy") { + final String currentStage = + exception.completedAuthenticationFlows == null + ? stages.first + : stages.firstWhere((stage) => + !exception.completedAuthenticationFlows.contains(stage) ?? + true); + + if (currentStage == "m.login.dummy") { _signUpAction(context, auth: { - "type": stages[currentStage], + "type": currentStage, "session": exception.session, }); } else { @@ -73,7 +74,7 @@ class _SignUpPasswordState extends State { AppRoute.defaultRoute( context, AuthWebView( - stages[currentStage], + currentStage, exception.session, () => _signUpAction(context, auth: { "session": exception.session,