Skip to content
This repository was archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
feat: add in logout endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanTheAllmighty committed Apr 27, 2019
1 parent e15c3e2 commit b3983da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ dockerHubAPI.login(process.env.DOCKER_HUB_USERNAME, process.env.DOCKER_HUB_PASSW
});
```

### logout()
This logs you out of Docker Hub.

No response is sent back, but any issues will throw.

### setLoginToken(token)
This works similar to above, but uses an existing login token so that you don't need to make a login request.

Expand Down
32 changes: 24 additions & 8 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@
}.bind(this),
);
},
/**
* This logs you out of Docker Hub.
*
* @returns {Promise}
*/
logout: function() {
return new Promise(
function(resolve, reject) {
if (!loggedInToken) {
return reject(
new Error(
'No login token found! Please login() or setLoginToken() to continue!',
),
);
}

this.makePostRequest('logout/')
.then(function() {
return resolve();
})
.catch(reject);
}.bind(this),
);
},
/**
* This gets information about the current logged in user.
*
Expand Down Expand Up @@ -1425,14 +1449,6 @@
makePostRequest(path, data, extract) {
return new Promise(
function(resolve, reject) {
if (!data || typeof data !== 'object') {
return reject(
new Error(
'Data must be passed to all POST requests in the form of an object!',
),
);
}

request(
this.makeRequestParams('post', path, data),
function(err, res, body) {
Expand Down

0 comments on commit b3983da

Please sign in to comment.