-
Notifications
You must be signed in to change notification settings - Fork 1
/
mmp.js
35 lines (32 loc) · 878 Bytes
/
mmp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// @ts-nocheck
'use strict'
const debug = require('debug')('laser:mmp')
const agent = require('superagent-promise')
const _ = require('underscore')
const config = require('./config')
module.exports.checkAuth = function (service, id) {
return agent('POST', config.mmpUrl)
.send({ service, id })
.set('X-Api-Key', config.mmpApiKey)
.end()
.then(function (res) {
return JSON.parse(res.text)
})
.catch(function (err) {
//Log this for now and proceed to the next promise
console.error(err)
return { valid: false, error: true }
})
.then(function (user) {
debug(user)
let haslaser = false
if (user?.valid && user.privileges) {
_.each(user.privileges, function (priv) {
if (priv.code === 'laser') {
haslaser = true
}
})
}
return haslaser
})
}