Add more typers to useInteractiveLogin

otherwise apparently Typescript can't trace the MatrixClient type
through.
This commit is contained in:
David Baker 2022-06-01 09:59:59 +01:00
parent 626fdb9f79
commit 7ee2f630db

View file

@ -16,12 +16,19 @@ 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) => {
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({
@ -39,7 +46,12 @@ export const useInteractiveLogin = () =>
/* eslint-disable camelcase */
const { user_id, access_token, device_id } =
await interactiveAuth.attemptAuth();
const session = { user_id, access_token, device_id };
const session = {
user_id,
access_token,
device_id,
passwordlessUser: false,
};
const client = await initClient({
baseUrl: defaultHomeserver,
@ -50,6 +62,4 @@ export const useInteractiveLogin = () =>
/* eslint-enable camelcase */
return [client, session];
},
[]
);
}, []);