Skip to content

Commit

Permalink
Made the max age a const
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 31, 2019
1 parent 310344b commit 6b6ca79
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const tough = require('tough-cookie')
axiosCookieJarSupport(axios)
const cookieJar = new tough.CookieJar()

// Cookie and session names
// Cookie and session defaults
const cookieName = 'session_token'
const defaultMaxAge = '172800' // From API session cookie time
const internalHeaderKey = 'x-user-session-token'
const version = 'v1'

Expand Down Expand Up @@ -211,14 +212,14 @@ function wrapAxios (t) {
axios.interceptors.request.use(function (config) {
// Are we making a request with a custom session token?
if (typeof config.headers[internalHeaderKey] !== 'undefined') {
config.jar.setCookie(cookieName + '=' + config.headers[internalHeaderKey] + '; Max-Age=172800; Path=/; HttpOnly;', config.url, function (err, cookies) {
config.jar.setCookie(cookieName + '=' + config.headers[internalHeaderKey] + '; Max-Age=' + defaultMaxAge + '; Path=/; HttpOnly;', config.url, function (err, cookies) {
if (err) {
throw Error(err.message)
}
})
config.headers[internalHeaderKey] = 'set'
} else if (t.session.apiToken) {
config.jar.setCookie(cookieName + '=' + t.session.apiToken + '; Max-Age=172800; Path=/; HttpOnly;', config.url, function (err, cookies) {
config.jar.setCookie(cookieName + '=' + t.session.apiToken + '; Max-Age=' + defaultMaxAge + '; Path=/; HttpOnly;', config.url, function (err, cookies) {
if (err) {
throw Error(err.message)
}
Expand Down Expand Up @@ -349,7 +350,7 @@ async function getUserBalance (t, userId) {
// getUser will get a user by ID or email address
//
// For more information: https://docs.tonicpow.com/#e6f764a2-5a91-4680-aa5e-03409dd878d8
async function getUser (t, userId, email) {
async function getUser (t, userId = 0, email = '') {
let url = t.config.apiUrl + version + '/users/details?'

if (userId && userId > 0) {
Expand Down

0 comments on commit 6b6ca79

Please sign in to comment.