UNPKG

943 BJavaScriptView Raw
1var request = require('request');
2var Promise = require('bluebird');
3var evoke = require('./evoke');
4var log = require('./log');
5
6module.exports = {
7 check: function(domo){
8 return new Promise(function(resolve, reject){
9 var options = {
10 url: 'https://' + domo.instance + '/auth/validate',
11 method: 'GET'
12 };
13
14 domo.processRequest(options)
15 .then(function(res) {
16 try{
17 var isValid = JSON.parse(res.body).isValid;
18 if(isValid){
19 resolve(true);
20 }
21 else {
22 reject(false);
23 }
24 }
25 catch(e){
26 // couldn't parse as JSON which means the service doesn't exist yet.
27 // TODO: remove this once the /domoweb/auth/validate service has shipped to prod
28 resolve(true);
29 }
30 })
31 .catch(evoke(log.clientRequestFailed, 'Not authenticated'));
32 });
33 }
34}