diff --git a/src/domain/LoginViewModel.js b/src/domain/LoginViewModel.js index d75a715e..5e0702da 100644 --- a/src/domain/LoginViewModel.js +++ b/src/domain/LoginViewModel.js @@ -72,6 +72,7 @@ export class LoginViewModel 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/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 85aa979c..4511d982 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -43,14 +43,6 @@ export const LoginFailure = createEnum( "Unknown", ); -function normalizeHomeserver(homeServer) { - try { - return new URL(homeServer).origin; - } catch (err) { - return new URL(`https://${homeServer}`).origin; - } -} - export class SessionContainer { constructor({platform, olmPromise, workerPromise}) { this._platform = platform; @@ -113,7 +105,6 @@ export class SessionContainer { } async queryLogin(homeServer) { - homeServer = normalizeHomeserver(homeServer); const hsApi = new HomeServerApi({homeServer, request: this._platform.request}); const response = await hsApi.queryLogin().response(); return this.parseLoginOptions(response, homeServer); @@ -129,15 +120,14 @@ export class SessionContainer { let sessionInfo; try { const request = this._platform.request; - const homeServer = normalizeHomeserver(loginMethod.homeServer); - const hsApi = new HomeServerApi({homeServer, request}); + const hsApi = new HomeServerApi({homeServer: loginMethod.homeServer, request}); const loginData = await loginMethod.login(hsApi, "Hydrogen", log); const sessionId = this.createNewSessionId(); sessionInfo = { id: sessionId, deviceId: loginData.device_id, userId: loginData.user_id, - homeServer: homeServer, + homeServer: loginMethod.homeServer, accessToken: loginData.access_token, lastUsed: clock.now() };