Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 1d41b95

Browse files
committed
types: improve authdata types
1 parent 0a3ba99 commit 1d41b95

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/components/structures/InteractiveAuth.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ import Spinner from "../views/elements/Spinner";
3131

3232
export const ERROR_USER_CANCELLED = new Error("User cancelled auth session");
3333

34+
type InteractiveAuthCallbackSuccess = (
35+
success: true,
36+
response: IAuthData,
37+
extra?: { emailSid?: string, clientSecret?: string }
38+
) => void;
39+
type InteractiveAuthCallbackFailure = (
40+
success: false,
41+
response: IAuthData | Error,
42+
) => void;
43+
export type InteractiveAuthCallback = InteractiveAuthCallbackSuccess & InteractiveAuthCallbackFailure;
44+
3445
interface IProps {
3546
// matrix client to use for UI auth requests
3647
matrixClient: MatrixClient;
@@ -66,11 +77,7 @@ interface IProps {
6677
// the auth session.
6778
// * clientSecret {string} The client secret used in auth
6879
// sessions with the ID server.
69-
onAuthFinished(
70-
status: boolean,
71-
result: IAuthData | Error,
72-
extra?: { emailSid?: string, clientSecret?: string },
73-
): void;
80+
onAuthFinished: InteractiveAuthCallback;
7481
// As js-sdk interactive-auth
7582
requestEmailToken?(email: string, secret: string, attempt: number, session: string): Promise<{ sid: string }>;
7683
// Called when the stage changes, or the stage's phase changes. First

src/components/structures/auth/Registration.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { createClient } from 'matrix-js-sdk/src/matrix';
17+
import { AuthType, createClient } from 'matrix-js-sdk/src/matrix';
1818
import React, { Fragment, ReactNode } from 'react';
1919
import { MatrixClient } from "matrix-js-sdk/src/client";
2020
import classNames from "classnames";
@@ -34,7 +34,7 @@ import RegistrationForm from '../../views/auth/RegistrationForm';
3434
import AccessibleButton from '../../views/elements/AccessibleButton';
3535
import AuthBody from "../../views/auth/AuthBody";
3636
import AuthHeader from "../../views/auth/AuthHeader";
37-
import InteractiveAuth from "../InteractiveAuth";
37+
import InteractiveAuth, { InteractiveAuthCallback } from "../InteractiveAuth";
3838
import Spinner from "../../views/elements/Spinner";
3939
import { AuthHeaderDisplay } from './header/AuthHeaderDisplay';
4040
import { AuthHeaderProvider } from './header/AuthHeaderProvider';
@@ -294,10 +294,10 @@ export default class Registration extends React.Component<IProps, IState> {
294294
);
295295
};
296296

297-
private onUIAuthFinished = async (success: boolean, response: any) => {
297+
private onUIAuthFinished: InteractiveAuthCallback = async (success, response) => {
298298
debuglog("Registration: ui authentication finished: ", { success, response });
299299
if (!success) {
300-
let errorText = response.message || response.toString();
300+
let errorText: ReactNode = response.message || response.toString();
301301
// can we give a better error message?
302302
if (response.errcode === 'M_RESOURCE_LIMIT_EXCEEDED') {
303303
const errorTop = messageForResourceLimitError(
@@ -320,10 +320,10 @@ export default class Registration extends React.Component<IProps, IState> {
320320
<p>{ errorTop }</p>
321321
<p>{ errorDetail }</p>
322322
</div>;
323-
} else if (response.required_stages && response.required_stages.indexOf('m.login.msisdn') > -1) {
323+
} else if (response.required_stages && response.required_stages.indexOf(AuthType.Msisdn) > -1) {
324324
let msisdnAvailable = false;
325325
for (const flow of response.available_flows) {
326-
msisdnAvailable = msisdnAvailable || flow.stages.includes('m.login.msisdn');
326+
msisdnAvailable = msisdnAvailable || flow.stages.includes(AuthType.Msisdn);
327327
}
328328
if (!msisdnAvailable) {
329329
errorText = _t('This server does not support authentication with a phone number.');

0 commit comments

Comments
 (0)