From 0c4c43305105dc92029611cfa0c5e962c6d33345 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Mon, 20 Jan 2020 19:51:56 -0500 Subject: [PATCH] Remove user token on logout --- lib/api.js | 12 +++++++++++- package.json | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/api.js b/lib/api.js index 7668d3b..aad0912 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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 @@ -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)) } @@ -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)) } diff --git a/package.json b/package.json index 232b778..4e55ebf 100644 --- a/package.json +++ b/package.json @@ -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": {