Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 35 additions & 2 deletions dist/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,34 @@ Kuzzle.prototype.connect = function () {
return this;
};

/**
* Set the jwtToken used to query kuzzle
* @param token
* @returns {Kuzzle}
*/
Kuzzle.prototype.setJwtToken = function(token) {
this.jwtToken = token;
return this;
};

/**
* Get the jwtToken used by kuzzle
* @returns {Kuzzle}
*/
Kuzzle.prototype.getJwtToken = function() {
return this.jwtToken;
};

/**
* Send login request to kuzzle with credentials
* If login success, store the jwtToken into kuzzle object
*
* @param strategy
* @param credentials
* @param expiresIn
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {
var
self = this,
Expand All @@ -625,7 +652,7 @@ Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {

this.query({controller: 'auth', action: 'login'}, {body: request}, {}, function(error, response) {
if (error === null) {
self.jwtToken = response.jwt;
self.setJwtToken(response.result.jwt);
renewAllSubscriptions.call(self);

if (typeof cb === 'function') {
Expand All @@ -643,6 +670,12 @@ Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {
return self;
};

/**
* Send logout request to kuzzle with jwtToken.
*
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.logout = function (cb) {
var
self = this,
Expand All @@ -655,7 +688,7 @@ Kuzzle.prototype.logout = function (cb) {

this.query({controller: 'auth', action: 'logout'}, request, {}, function(error) {
if (error === null) {
self.jwtToken = undefined;
self.setJwtToken(undefined);

if (typeof cb === 'function') {
cb(null, self);
Expand Down
2 changes: 1 addition & 1 deletion dist/kuzzle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kuzzle.min.map

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions src/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,34 @@ Kuzzle.prototype.connect = function () {
return this;
};

/**
* Set the jwtToken used to query kuzzle
* @param token
* @returns {Kuzzle}
*/
Kuzzle.prototype.setJwtToken = function(token) {
this.jwtToken = token;
return this;
};

/**
* Get the jwtToken used by kuzzle
* @returns {Kuzzle}
*/
Kuzzle.prototype.getJwtToken = function() {
return this.jwtToken;
};

/**
* Send login request to kuzzle with credentials
* If login success, store the jwtToken into kuzzle object
*
* @param strategy
* @param credentials
* @param expiresIn
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {
var
self = this,
Expand All @@ -350,7 +377,7 @@ Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {

this.query({controller: 'auth', action: 'login'}, {body: request}, {}, function(error, response) {
if (error === null) {
self.jwtToken = response.jwt;
self.setJwtToken(response.result.jwt);
renewAllSubscriptions.call(self);

if (typeof cb === 'function') {
Expand All @@ -368,6 +395,12 @@ Kuzzle.prototype.login = function (strategy, credentials, expiresIn, cb) {
return self;
};

/**
* Send logout request to kuzzle with jwtToken.
*
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.logout = function (cb) {
var
self = this,
Expand All @@ -380,7 +413,7 @@ Kuzzle.prototype.logout = function (cb) {

this.query({controller: 'auth', action: 'logout'}, request, {}, function(error) {
if (error === null) {
self.jwtToken = undefined;
self.setJwtToken(undefined);

if (typeof cb === 'function') {
cb(null, self);
Expand Down
2 changes: 1 addition & 1 deletion test/kuzzle/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ describe('Kuzzle constructor', () => {
});

kuzzle.query = function(queryArgs, query, options, cb) {
cb(null, { jwt: 'test-toto'});
cb(null, { result: {jwt: 'test-toto'}});
};

kuzzle.login('local', loginCredentials, '1h', function(error, k) {
Expand Down