diff --git a/src/viewmodels/AccountSetupViewModel.ts b/src/viewmodels/AccountSetupViewModel.ts
index 4693f55d5885b4a7fbcacd2586ffc68de4e8dcf3..2444ef326266fdf33e6f7515d0b3c8fded006b55 100644
--- a/src/viewmodels/AccountSetupViewModel.ts
+++ b/src/viewmodels/AccountSetupViewModel.ts
@@ -28,13 +28,13 @@ export class AccountSetupViewModel extends ViewModel {
                 this._registration = await this._client.startRegistration(this._homeserver, username, this._password, "Chatterbox");
                 this._startStage = await this._registration.start();
                 let stage = this._startStage;
-                while (stage.type !== "m.login.terms") {
+                while (stage && stage.type !== "m.login.terms") {
                     stage = stage.nextStage;
-                    if (!stage) {
-                        // If terms login stage is not found, go straight to completeRegistration()
-                        this.completeRegistration();
-                        return;
-                    }
+                }
+                if (!stage) {
+                    // If terms login stage is not found, go straight to completeRegistration()
+                    this.completeRegistration();
+                    return;
                 }
                 this._privacyPolicyLink = stage.privacyPolicy.en?.url;
                 this.emitChange("privacyPolicyLink");