diff --git a/src/domain/login/LoginViewModel.js b/src/domain/login/LoginViewModel.js index ba86baf5..4f3b3cbd 100644 --- a/src/domain/login/LoginViewModel.js +++ b/src/domain/login/LoginViewModel.js @@ -17,7 +17,6 @@ limitations under the License. import {ViewModel} from "../ViewModel.js"; import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js"; import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js"; -import {normalizeHomeserver} from "./common.js"; import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js"; export class LoginViewModel extends ViewModel { @@ -46,10 +45,9 @@ export class LoginViewModel extends ViewModel { this.emitChange("completeSSOLoginViewModel"); } else { - const defaultHomeServer = normalizeHomeserver(this._defaultHomeServer); - await this.queryLogin(defaultHomeServer); + await this.queryLogin(this._defaultHomeServer); this._showPasswordLogin(); - this._showSSOLogin(defaultHomeServer); + this._showSSOLogin(this._defaultHomeServer); } } @@ -80,9 +78,8 @@ export class LoginViewModel extends ViewModel { } async _onHomeServerChange(homeserver) { - const normalizedHS = normalizeHomeserver(homeserver); - await this.queryLogin(normalizedHS); - this._showSSOLogin(normalizedHS); + await this.queryLogin(homeserver); + this._showSSOLogin(homeserver); } childOptions(options) { diff --git a/src/domain/login/PasswordLoginViewModel.js b/src/domain/login/PasswordLoginViewModel.js index 2b4700d3..496d431d 100644 --- a/src/domain/login/PasswordLoginViewModel.js +++ b/src/domain/login/PasswordLoginViewModel.js @@ -17,7 +17,6 @@ limitations under the License. import {ViewModel} from "../ViewModel.js"; import {SessionLoadViewModel} from "../SessionLoadViewModel.js"; import {ObservableValue} from "../../observable/ObservableValue.js"; -import {normalizeHomeserver} from "./common.js"; export class PasswordLoginViewModel extends ViewModel { constructor(options) { @@ -50,7 +49,6 @@ export class PasswordLoginViewModel extends ViewModel { } async login(username, password, homeserver) { - homeserver = normalizeHomeserver(homeserver); this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription); if (this._loadViewModel) { this._loadViewModel = this.disposeTracked(this._loadViewModel); diff --git a/src/domain/login/common.js b/src/domain/login/common.js deleted file mode 100644 index 8bc162e9..00000000 --- a/src/domain/login/common.js +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2021 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -export function normalizeHomeserver(homeServer) { - try { - return new URL(homeServer).origin; - } catch (err) { - return new URL(`https://${homeServer}`).origin; - } -} diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 7492d0c3..3aaa782b 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -27,6 +27,14 @@ import {PasswordLoginMethod} from "./login/PasswordLoginMethod.js"; import {TokenLoginMethod} from "./login/TokenLoginMethod.js"; import {SSOLoginHelper} from "./login/SSOLoginHelper.js"; +function normalizeHomeserver(homeServer) { + try { + return new URL(homeServer).origin; + } catch (err) { + return new URL(`https://${homeServer}`).origin; + } +} + export const LoadStatus = createEnum( "NotLoading", "Login", @@ -114,9 +122,10 @@ export class SessionContainer { } async queryLogin(homeServer) { - const hsApi = new HomeServerApi({homeServer, request: this._platform.request}); + const normalizedHS = normalizeHomeserver(homeServer); + const hsApi = new HomeServerApi({homeServer: normalizedHS, request: this._platform.request}); const response = await hsApi.queryLogin().response(); - return this.parseLoginOptions(response, homeServer); + return this.parseLoginOptions(response, normalizedHS); } async startWithLogin(loginMethod) {