Use type from server

This commit is contained in:
RMidhunSuresh 2022-02-16 13:21:04 +05:30
parent ed151c8567
commit 60bc4450f3

View file

@ -18,7 +18,7 @@ import type {HomeServerApi} from "../net/HomeServerApi";
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage"; import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
import {DummyAuth} from "./stages/DummyAuth"; import {DummyAuth} from "./stages/DummyAuth";
import {TermsAuth} from "./stages/TermsAuth"; import {TermsAuth} from "./stages/TermsAuth";
import {TokenAuth, TOKEN_AUTH_TYPE} from "./stages/TokenAuth"; import {TokenAuth} from "./stages/TokenAuth";
import type { import type {
AccountDetails, AccountDetails,
RegistrationFlow, RegistrationFlow,
@ -94,7 +94,9 @@ export class Registration {
this._sessionInfo = response; this._sessionInfo = response;
return undefined; return undefined;
case 401: case 401:
if (response.completed?.includes(currentStage.type)) { // Support unstable prefix for TokenAuth
const typeFromServer = (currentStage as TokenAuth).typeFromServer;
if (response.completed?.includes(typeFromServer ?? currentStage.type)) {
return currentStage.nextStage; return currentStage.nextStage;
} }
else { else {
@ -109,8 +111,9 @@ export class Registration {
return new DummyAuth(session, params?.[type]); return new DummyAuth(session, params?.[type]);
case "m.login.terms": case "m.login.terms":
return new TermsAuth(session, params?.[type]); return new TermsAuth(session, params?.[type]);
case TOKEN_AUTH_TYPE: case "org.matrix.msc3231.login.registration_token":
return new TokenAuth(session, params?.[type]); case "m.login.registration_token":
return new TokenAuth(session, params?.[type], type);
default: default:
throw new Error(`Unknown stage: ${type}`); throw new Error(`Unknown stage: ${type}`);
} }