Comparing version 5.4.0 to 5.5.0
{ | ||
"name": "ers-http", | ||
"version": "5.4.0", | ||
"version": "5.5.0", | ||
"description": "", | ||
@@ -29,5 +29,6 @@ "main": "index.js", | ||
"numeral": "^2.0.6", | ||
"request": "^2.88.0", | ||
"request-promise": "^4.2.4", | ||
"socket.io": "^2.2.0", | ||
"socket.io-redis": "^5.2.0", | ||
"superagent": "^4.0.0" | ||
"socket.io-redis": "^5.2.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -0,48 +1,45 @@ | ||
const request = require('request-promise') | ||
const request = require('superagent') | ||
module.exports = (options = {}) => { | ||
const { baseUrl } = options | ||
const { | ||
baseUrl, | ||
} = options | ||
if (!baseUrl) throw new Error('baseUrl required in restrict middleware') | ||
if (!baseUrl) throw new Error('baseUrl required in restrict middleware') | ||
return () => (req, res, next) => { | ||
const error = message => next(new Error(message)) | ||
return () => (req, res, next) => { | ||
let query = req.query || {} | ||
const error = (message) => next(new Error(message)) | ||
if (req.handshake) { | ||
query = req.handshake.query | ||
next = res | ||
} | ||
let query = req.query || {} | ||
const access_token = query.access_token | ||
if (req.handshake) { | ||
query = req.handshake.query | ||
next = res | ||
} | ||
if (!access_token) return error('access_token required') | ||
const access_token = query.access_token | ||
request({ | ||
url: baseUrl + '/account/me/id', | ||
qs: { access_token }, | ||
json: true, | ||
}) | ||
.then(body => { | ||
const data = body || {} | ||
if (!access_token) return error('access_token required') | ||
req.session = { | ||
...req.session, | ||
userId: String(data.user_id), | ||
groupId: String(data.group_id), | ||
productId: String(data.product_id), | ||
roleId: String(data.role_id), | ||
lang: data.lang, | ||
paid: data.paid, | ||
accessToken: access_token, | ||
} | ||
request.get(baseUrl + '/account/me/id') | ||
.query({access_token}) | ||
.then(res => { | ||
if (res.error) return error('access_token invalid') | ||
const data = res.body || {} | ||
req.session = { | ||
...req.session, | ||
userId: String(data.user_id), | ||
groupId: String(data.group_id), | ||
productId: String(data.product_id), | ||
roleId: String(data.role_id), | ||
lang: data.lang, | ||
accessToken: access_token | ||
} | ||
next() | ||
}) | ||
.catch(e => error('access_token fetching error')) | ||
} | ||
next() | ||
}) | ||
.catch(e => error('access_token invalid')) | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
216
7630
12
+ Addedrequest@^2.88.0
+ Addedrequest-promise@^4.2.4
- Removedsuperagent@^4.0.0
- Removedcookiejar@2.1.4(transitive)
- Removeddebug@4.3.7(transitive)
- Removedformidable@1.2.6(transitive)
- Removedmime@2.6.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsuperagent@4.1.0(transitive)