Add more typers to useInteractiveLogin
otherwise apparently Typescript can't trace the MatrixClient type through.
This commit is contained in:
parent
626fdb9f79
commit
7ee2f630db
1 changed files with 39 additions and 29 deletions
|
@ -16,40 +16,50 @@ limitations under the License.
|
||||||
|
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import matrix, { InteractiveAuth } from "matrix-js-sdk/src/browser-index";
|
import matrix, { InteractiveAuth } from "matrix-js-sdk/src/browser-index";
|
||||||
|
import { MatrixClient } from "matrix-js-sdk";
|
||||||
|
|
||||||
import { initClient, defaultHomeserver } from "../matrix-utils";
|
import { initClient, defaultHomeserver } from "../matrix-utils";
|
||||||
|
import { Session } from "../ClientContext";
|
||||||
|
|
||||||
export const useInteractiveLogin = () =>
|
export const useInteractiveLogin = () =>
|
||||||
useCallback(
|
useCallback<
|
||||||
async (homeserver: string, username: string, password: string) => {
|
(
|
||||||
const authClient = matrix.createClient(homeserver);
|
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({
|
const interactiveAuth = new InteractiveAuth({
|
||||||
matrixClient: authClient,
|
matrixClient: authClient,
|
||||||
doRequest: () =>
|
doRequest: () =>
|
||||||
authClient.login("m.login.password", {
|
authClient.login("m.login.password", {
|
||||||
identifier: {
|
identifier: {
|
||||||
type: "m.id.user",
|
type: "m.id.user",
|
||||||
user: username,
|
user: username,
|
||||||
},
|
},
|
||||||
password,
|
password,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
const { user_id, access_token, device_id } =
|
const { user_id, access_token, device_id } =
|
||||||
await interactiveAuth.attemptAuth();
|
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({
|
const client = await initClient({
|
||||||
baseUrl: defaultHomeserver,
|
baseUrl: defaultHomeserver,
|
||||||
accessToken: access_token,
|
accessToken: access_token,
|
||||||
userId: user_id,
|
userId: user_id,
|
||||||
deviceId: device_id,
|
deviceId: device_id,
|
||||||
});
|
});
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
|
|
||||||
return [client, session];
|
return [client, session];
|
||||||
},
|
}, []);
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue