Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
headers = Object.assign({}, headers, {
'X-Request-Id': uuid(),
Accept: 'application/json',
'Content-Type': 'application/json'
})
if (
typeof require !== 'undefined' &&
typeof this.token !== 'undefined' &&
!!this.token
) {
let cookieConf = require('conf/conf')
Object.assign(headers, {
Cookie: !!this.token
? `${cookieConf.name}_token=${this
.token}; Max-Age=${cookieConf.maxAge}; Domain=${cookieConf.domain}; Path=${cookieConf.path};${cookieConf.httpOnly
? ' httpOnly;'
: ''}${cookieConf ? 'Secure;' : ''}`
: false
})
}
options = Object.assign({}, options, {
headers
})
if (typeof require !== 'undefined') {
Object.assign(options, { agent: require('middleware/auth/agent') })
}
return fetch(url, options)
.then(this.checkStatus)
.then(this.buildResponse.bind(this, url))
.catch(this.manageError)
return stackTokenCalls(req, ip).spread((user, token) => {
let options = Object.assign(
{},
{
maxAge: conf.maxAge,
path: conf.path
},
conf.domain && {
domain: conf.domain
},
conf.secure && {
secure: conf.secure
},
conf.httpOnly && {
httpOnly: conf.httpOnly
}
)
if (token) {
res.cookie(`${conf.name}_token`, token, options)
}
req.user = user.data
req.token = token
return next()
})
}
return stackTokenCalls(req, ip).spread((user, token) => {
let options = Object.assign(
{},
{
maxAge: conf.maxAge,
path: conf.path
},
conf.domain && {
domain: conf.domain
},
conf.secure && {
secure: conf.secure
},
conf.httpOnly && {
httpOnly: conf.httpOnly
}
)
if (token) {
res.cookie(`${conf.name}_token`, token, options)
}
req.user = user.data
req.token = token
return next()
})
}