From 112c0eacbadc26c56c173f703abe1de48363855f Mon Sep 17 00:00:00 2001 From: RMidhunSuresh <hi@midhun.dev> Date: Wed, 27 Apr 2022 14:58:03 +0530 Subject: [PATCH] Fix bug --- src/viewmodels/AccountSetupViewModel.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts index 2444ef3..20962a0 100644 --- a/src/viewmodels/AccountSetupViewModel.ts +++ b/src/viewmodels/AccountSetupViewModel.ts @@ -1,3 +1,4 @@ + import { ViewModel, Client, LoadStatus } from "hydrogen-view-sdk"; import { IChatterboxConfig } from "../types/IChatterboxConfig"; import { generatePassword, generateUsername } from "../random"; @@ -25,7 +26,22 @@ export class AccountSetupViewModel extends ViewModel { for (let i = 0; i < maxAttempts; ++i) { try { const username = `${this._config.username_prefix}-${generateUsername(10)}`; - this._registration = await this._client.startRegistration(this._homeserver, username, this._password, "Chatterbox"); + const flowSelector = (flows) => { + const allowedStages = [ + "m.login.registration_token", + "org.matrix.msc3231.login.registration_token", + "m.login.terms", + "m.login.dummy" + ]; + for (const flow of flows) { + // Find the first flow that does not contain any unsupported stages + const containsUnsupportedStage = flow.stages.some(stage => !allowedStages.includes(stage)); + if (!containsUnsupportedStage) { + return flow; + } + } + } + this._registration = await this._client.startRegistration(this._homeserver, username, this._password, "Chatterbox", flowSelector); this._startStage = await this._registration.start(); let stage = this._startStage; while (stage && stage.type !== "m.login.terms") { -- GitLab