From 7ee2f630db0e97f4f61c79a2366ae2f75c958fb8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 1 Jun 2022 09:59:59 +0100 Subject: [PATCH] Add more typers to useInteractiveLogin otherwise apparently Typescript can't trace the MatrixClient type through. --- src/auth/useInteractiveLogin.ts | 68 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/auth/useInteractiveLogin.ts b/src/auth/useInteractiveLogin.ts index b4e3ad2..2cfe78c 100644 --- a/src/auth/useInteractiveLogin.ts +++ b/src/auth/useInteractiveLogin.ts @@ -16,40 +16,50 @@ limitations under the License. import { useCallback } from "react"; import matrix, { InteractiveAuth } from "matrix-js-sdk/src/browser-index"; +import { MatrixClient } from "matrix-js-sdk"; import { initClient, defaultHomeserver } from "../matrix-utils"; +import { Session } from "../ClientContext"; export const useInteractiveLogin = () => - useCallback( - async (homeserver: string, username: string, password: string) => { - const authClient = matrix.createClient(homeserver); + useCallback< + ( + homeserver: string, + username: string, + password: string + ) => Promise<[MatrixClient, Session]> + >(async (homeserver: string, username: string, password: string) => { + const authClient = matrix.createClient(homeserver); - const interactiveAuth = new InteractiveAuth({ - matrixClient: authClient, - doRequest: () => - authClient.login("m.login.password", { - identifier: { - type: "m.id.user", - user: username, - }, - password, - }), - }); + const interactiveAuth = new InteractiveAuth({ + matrixClient: authClient, + doRequest: () => + authClient.login("m.login.password", { + identifier: { + type: "m.id.user", + user: username, + }, + password, + }), + }); - /* eslint-disable camelcase */ - const { user_id, access_token, device_id } = - await interactiveAuth.attemptAuth(); - const session = { user_id, access_token, device_id }; + /* eslint-disable camelcase */ + const { user_id, access_token, device_id } = + await interactiveAuth.attemptAuth(); + const session = { + user_id, + access_token, + device_id, + passwordlessUser: false, + }; - const client = await initClient({ - baseUrl: defaultHomeserver, - accessToken: access_token, - userId: user_id, - deviceId: device_id, - }); - /* eslint-enable camelcase */ + const client = await initClient({ + baseUrl: defaultHomeserver, + accessToken: access_token, + userId: user_id, + deviceId: device_id, + }); + /* eslint-enable camelcase */ - return [client, session]; - }, - [] - ); + return [client, session]; + }, []);