From 2a04459bb2fdad6ab1e7bbbe694ba457f32cb06b Mon Sep 17 00:00:00 2001 From: Sergii Stotskyi Date: Tue, 28 May 2019 17:45:02 +0300 Subject: [PATCH] fix(login): saves access_token and user_id after login for all login types Signed-off-by: Sergii Stotskyi Fixes #876 --- spec/unit/login.spec.js | 25 +++++++++++++++++++++++++ src/base-apis.js | 3 +-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 spec/unit/login.spec.js diff --git a/spec/unit/login.spec.js b/spec/unit/login.spec.js new file mode 100644 index 000000000..6cc83411d --- /dev/null +++ b/spec/unit/login.spec.js @@ -0,0 +1,25 @@ +import expect from 'expect'; +import TestClient from '../TestClient'; + +describe('Login request', function() { + let client; + + beforeEach(function() { + client = new TestClient(); + }); + + afterEach(function() { + client.stop(); + }); + + it('should store "access_token" and "user_id" if found in response', async function() { + const response = { user_id: 1, access_token: Date.now().toString(16) }; + + client.httpBackend.when('POST', '/login').respond(200, response); + client.httpBackend.flush('/login', 1, 100); + await client.client.login('m.login.any', { user: 'test', password: '12312za' }); + + expect(client.client.getAccessToken()).toBe(response.access_token); + expect(client.client.getUserId()).toBe(response.user_id); + }); +}); diff --git a/src/base-apis.js b/src/base-apis.js index a799ffa85..a0109b3c1 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -263,8 +263,7 @@ MatrixBaseApis.prototype.login = function(loginType, data, callback) { return this._http.authedRequest( (error, response) => { - if (loginType === "m.login.password" && response && - response.access_token && response.user_id) { + if (response && response.access_token && response.user_id) { this._http.opts.accessToken = response.access_token; this.credentials = { userId: response.user_id,