1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

Factor out common login code (#2307)

Removes the duplication between the various points where we send off a login
request and parse the response.
This commit is contained in:
Richard van der Hoff
2018-12-05 17:39:38 +01:00
committed by GitHub
parent a3382eb655
commit c553323d5a
2 changed files with 42 additions and 78 deletions

View File

@@ -32,6 +32,7 @@ import Modal from './Modal';
import sdk from './index';
import ActiveWidgetStore from './stores/ActiveWidgetStore';
import PlatformPeg from "./PlatformPeg";
import {sendLoginRequest} from "./Login";
/**
* Called at startup, to attempt to build a logged-in Matrix session. It tries
@@ -129,27 +130,17 @@ export function attemptTokenLogin(queryParams, defaultDeviceDisplayName) {
return Promise.resolve(false);
}
// create a temporary MatrixClient to do the login
const client = Matrix.createClient({
baseUrl: queryParams.homeserver,
});
return client.login(
return sendLoginRequest(
queryParams.homeserver,
queryParams.identityServer,
"m.login.token", {
token: queryParams.loginToken,
initial_device_display_name: defaultDeviceDisplayName,
},
).then(function(data) {
).then(function(creds) {
console.log("Logged in with token");
return _clearStorage().then(() => {
_persistCredentialsToLocalStorage({
userId: data.user_id,
deviceId: data.device_id,
accessToken: data.access_token,
homeserverUrl: queryParams.homeserver,
identityServerUrl: queryParams.identityServer,
guest: false,
});
_persistCredentialsToLocalStorage(creds);
return true;
});
}).catch((err) => {