Last active
November 29, 2017 14:41
-
-
Save ihfazhillah/c1c4064ae2bd40559c369b48ac6d9bef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rp = require('request-promise') | |
module.exports = function(context, cb) { | |
const userInput = context.body.input; | |
const url = "THEURL" | |
const authorization = "Bearer THETOKEN" | |
rp({ | |
url: url, | |
method: "POST", | |
json: true, | |
headers: { | |
Authorization: authorization | |
}, | |
body: { | |
query: `query($username: String!){ | |
viewer{ | |
allUsers(where: {username: {eq: $username}}, first:1){ | |
edges{ | |
node{ | |
verified | |
} | |
} | |
} | |
} | |
}`, | |
variables: { | |
username: userInput.username | |
} | |
} | |
}).then(data => { | |
if(data.data.viewer.allUsers.edges.length){ | |
// if user with that username found, then check if it verified | |
const verified = data.data.viewer.allUsers.edges[0].node.verified | |
if(verified){ | |
// if yes, then make scaphold go to next step | |
cb(null, context.data) | |
return | |
} | |
// user not verified yet, create error message | |
return cb(new Error("user not verified"), null) | |
} | |
// user not found -> make scaphold go to next step | |
return cb(null, context.body.input) | |
}).catch(error => {return cb(error, null)}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment