Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions features/steps/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ Then(/^the collection(?: '(.*?)')? should exist$/, async function (collection) {
Then('the mapping of {string} should be updated', async function (collection) {
const mapping = await this.kuzzle.collection.getMapping(this.index, collection);

should(mapping[this.index].mappings[collection]).eql({
properties: {
gordon: {type: 'keyword'}
}
should(mapping[this.index].mappings[collection].properties).eql({
gordon: { type: 'keyword' }
});
});

Expand All @@ -129,7 +127,6 @@ Then('the specifications of {string} must not exist', async function (collection
catch (error) {
should(error.status).eql(404);
}

});

Then('they should be validated', function () {
Expand Down
4 changes: 4 additions & 0 deletions src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ class Kuzzle extends KuzzleEventEmitter {
return this.protocol.sslConnection;
}

get authenticated () {
return this.jwt !== null && this.jwt !== undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpicking) according to the jwt setter code, that property can never be null

}

/**
* Emit an event to all registered listeners
* An event cannot be emitted multiple times before a timeout has been reached.
Expand Down
17 changes: 10 additions & 7 deletions src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,19 @@ class AuthController extends BaseController {
throw new Error('Kuzzle.auth.login: strategy is required');
}

const
request = {
strategy,
expiresIn,
body: credentials,
action: 'login'
};
const request = {
strategy,
expiresIn,
body: credentials,
action: 'login'
};

return this.query(request, {queuable: false})
.then(response => {
try {
this.kuzzle.jwt = response.result.jwt;
this.kuzzle.jwtExpiresAt = response.result.expiresAt;

this.kuzzle.emit('loginAttempt', {success: true});
}
catch (err) {
Expand All @@ -180,6 +181,7 @@ class AuthController extends BaseController {
}, {queuable: false})
.then(() => {
this.kuzzle.jwt = undefined;
this.kuzzle.jwtExpiresAt = undefined;
});
}

Expand Down Expand Up @@ -247,6 +249,7 @@ class AuthController extends BaseController {
return this.query(query, options)
.then(response => {
this.kuzzle.jwt = response.result.jwt;
this.kuzzle.jwtExpiresAt = response.result.expiresAt;

return response.result;
});
Expand Down
1 change: 1 addition & 0 deletions src/controllers/realtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class RealTimeController extends BaseController {

this.subscriptions = {};
this.kuzzle.jwt = undefined;
this.kuzzle.jwtExpiresAt = undefined;

const now = Date.now();
if ((now - this.lastExpirationTimestamp) > expirationThrottleDelay) {
Expand Down