Merge pull request #370 from vector-im/dbkr/avoid-browser-index-import
Fix app when built in production mode
This commit is contained in:
commit
ecb139721b
3 changed files with 23 additions and 10 deletions
|
@ -15,8 +15,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import matrix, { InteractiveAuth } from "matrix-js-sdk/src/browser-index";
|
import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth";
|
||||||
import { MatrixClient } from "matrix-js-sdk";
|
import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { initClient, defaultHomeserver } from "../matrix-utils";
|
import { initClient, defaultHomeserver } from "../matrix-utils";
|
||||||
import { Session } from "../ClientContext";
|
import { Session } from "../ClientContext";
|
||||||
|
@ -29,7 +29,7 @@ export const useInteractiveLogin = () =>
|
||||||
password: string
|
password: string
|
||||||
) => Promise<[MatrixClient, Session]>
|
) => Promise<[MatrixClient, Session]>
|
||||||
>(async (homeserver: string, username: string, password: string) => {
|
>(async (homeserver: string, username: string, password: string) => {
|
||||||
const authClient = matrix.createClient(homeserver);
|
const authClient = createClient(homeserver);
|
||||||
|
|
||||||
const interactiveAuth = new InteractiveAuth({
|
const interactiveAuth = new InteractiveAuth({
|
||||||
matrixClient: authClient,
|
matrixClient: authClient,
|
||||||
|
@ -41,11 +41,15 @@ export const useInteractiveLogin = () =>
|
||||||
},
|
},
|
||||||
password,
|
password,
|
||||||
}),
|
}),
|
||||||
|
stateUpdated: null,
|
||||||
|
requestEmailToken: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
// XXX: This claims to return an IAuthData which contains none of these
|
||||||
|
// things - the js-sdk types may be wrong?
|
||||||
|
/* eslint-disable camelcase,@typescript-eslint/no-explicit-any */
|
||||||
const { user_id, access_token, device_id } =
|
const { user_id, access_token, device_id } =
|
||||||
await interactiveAuth.attemptAuth();
|
(await interactiveAuth.attemptAuth()) as any;
|
||||||
const session = {
|
const session = {
|
||||||
user_id,
|
user_id,
|
||||||
access_token,
|
access_token,
|
||||||
|
|
|
@ -15,8 +15,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useEffect, useCallback, useRef } from "react";
|
import { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import matrix, { InteractiveAuth } from "matrix-js-sdk/src/browser-index";
|
import { InteractiveAuth } from "matrix-js-sdk/src/interactive-auth";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { initClient, defaultHomeserver } from "../matrix-utils";
|
import { initClient, defaultHomeserver } from "../matrix-utils";
|
||||||
import { Session } from "../ClientContext";
|
import { Session } from "../ClientContext";
|
||||||
|
@ -37,7 +37,7 @@ export const useInteractiveRegistration = (): [
|
||||||
|
|
||||||
const authClient = useRef<MatrixClient>();
|
const authClient = useRef<MatrixClient>();
|
||||||
if (!authClient.current) {
|
if (!authClient.current) {
|
||||||
authClient.current = matrix.createClient(defaultHomeserver);
|
authClient.current = createClient(defaultHomeserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -81,11 +81,14 @@ export const useInteractiveRegistration = (): [
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
requestEmailToken: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
// XXX: This claims to return an IAuthData which contains none of these
|
||||||
|
// things - the js-sdk types may be wrong?
|
||||||
|
/* eslint-disable camelcase,@typescript-eslint/no-explicit-any */
|
||||||
const { user_id, access_token, device_id } =
|
const { user_id, access_token, device_id } =
|
||||||
await interactiveAuth.attemptAuth();
|
(await interactiveAuth.attemptAuth()) as any;
|
||||||
|
|
||||||
const client = await initClient({
|
const client = await initClient({
|
||||||
baseUrl: defaultHomeserver,
|
baseUrl: defaultHomeserver,
|
||||||
|
|
|
@ -14,6 +14,12 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// We need to import this somewhere, once, so that the correct 'request'
|
||||||
|
// function gets set. It needs to be not in the same file as we use
|
||||||
|
// createClient, or the typescript transpiler gets confused about
|
||||||
|
// dependency references.
|
||||||
|
import "matrix-js-sdk/src/browser-index";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { createBrowserHistory } from "history";
|
import { createBrowserHistory } from "history";
|
||||||
|
|
Loading…
Reference in a new issue