Skip to content

Instantly share code, notes, and snippets.

@adnanrahic
Created May 8, 2018 14:17
Show Gist options
  • Save adnanrahic/e8b45fb452f5ce53d3907b9f184b22c8 to your computer and use it in GitHub Desktop.
Save adnanrahic/e8b45fb452f5ce53d3907b9f184b22c8 to your computer and use it in GitHub Desktop.
// Node.js v.8.10
module.exports.login = (event, context) => {
return connectToDatabase() // returning promise! :)
.then(() =>
login(JSON.parse(event.body)) // promise
)
.then(session => ({ // resolving the promise to an object
statusCode: 200,
body: JSON.stringify(session)
}))
.catch(err => ({ // or rejecting with an error
statusCode: 500,
body: JSON.stringify(err)
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment