From 1d4b079d0c815c712f4fe30e790bab16d6dadd7c Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Wed, 2 Feb 2022 13:58:03 +0530 Subject: [PATCH] Type RegistrationResponse --- src/matrix/registration/Registration.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/matrix/registration/Registration.ts b/src/matrix/registration/Registration.ts index dd19fae4..cd44dc38 100644 --- a/src/matrix/registration/Registration.ts +++ b/src/matrix/registration/Registration.ts @@ -23,11 +23,23 @@ export type RegistrationDetails = { password: string; initialDeviceDisplayName: string; inhibitLogin: boolean; -} +} -// todo: type this later export type RegistrationResponse = { - [key: string]: any; + completed: string[]; + flows: Record[]; + params: Record; + session: string; +} & error & success; + +type error = { + errcode: string; + error: string; +} +type success = { + user_id: string; + device_id: string; + access_token?: string; } export class Registration { @@ -52,6 +64,9 @@ export class Registration { parseStagesFromResponse(response: RegistrationResponse): BaseRegistrationStage { const { session, params } = response; const flow = response.flows.pop(); + if (!flow) { + throw new Error("No registration flows available!"); + } let firstStage: BaseRegistrationStage | undefined; let lastStage: BaseRegistrationStage; for (const stage of flow.stages) {