Skip to content

Instantly share code, notes, and snippets.

@ihfazhillah
Last active November 29, 2017 14:41
Show Gist options
  • Save ihfazhillah/c1c4064ae2bd40559c369b48ac6d9bef to your computer and use it in GitHub Desktop.
Save ihfazhillah/c1c4064ae2bd40559c369b48ac6d9bef to your computer and use it in GitHub Desktop.
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