Skip to content

Commit

Permalink
Remove user token on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 21, 2020
1 parent c5b2dae commit 0c4c433
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaultMaxAge = 172800
const internalHeaderKey = 'x-user-session-token'

// Current version for requests from the API
const pkgVersion = 'v0.1.49'
const pkgVersion = 'v0.1.51'
const apiVersion = 'v1'

// getOptions is a factory for axios default options
Expand Down Expand Up @@ -394,6 +394,13 @@ async function prolongSession (t, userSessionToken = '') {
//
// For more information: https://docs.tonicpow.com/#1dfeff1e-6c8d-4b32-904e-a19261b1f89e
async function endSession (t, userSessionToken = '') {

if (userSessionToken.length === 0 || userSessionToken === t.apiToken) {

// Clear local api token
t.apiToken = 'delete'
}

return tonicAxios.delete(t.config.apiUrl + apiVersion + '/auth/session', getOptions(userSessionToken))
}

Expand All @@ -416,6 +423,9 @@ async function logoutUser (t, userSessionToken = '') {
userSessionToken = t.session.userToken
}

// Clear local user token
t.userToken = 'delete'

return tonicAxios.delete(t.config.apiUrl + apiVersion + '/users/logout', getOptions(userSessionToken))
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tonicpow-js",
"version": "0.1.50",
"version": "0.1.51",
"description": "TonicPow API Library in JS - https://docs.tonicpow.com",
"main": "lib/api.js",
"repository": {
Expand Down

0 comments on commit 0c4c433

Please sign in to comment.