const https = require('https');
// Enter your Form.io project API key here, which will provide AWS Lambda requests
let apiKey = '--- YOUR FORM.IO PROJECT API KEY ---';
// The lambda event execution context.
exports.handler = (event, context, callback) => {
// The user will make a request to Lambda and provide his/her JWT Token
// We will now use the "current" endpoint within our project to determine the
// full user object from that token.
const requestUser = https.request({
hostname: 'examples.form.io',
'x-jwt-token': event.jwtToken
}, (requestUserResponse) => {
requestUserResponse.setEncoding('utf8');
requestUserResponse.on('data', (chunk) => user += chunk);
requestUserResponse.on('end', () => {
// We now have the full user object. Parse it as a JSON object.
// Here is where you could do something to validate the user...
// Such as, send a request to payment processor to validate payment
// Say that this user is now valid.
// Now perform a PUT reqeust to update the user record as an administrator.
// We will use the x-token header which utilizes the Project API key to perform
const updateUser = https.request({
hostname: 'examples.form.io',
path: '/user/submission/' + user._id,
'Content-Type' : 'application/json'
}, (updateUserResponse) => {
// The user is now updated and valid.
updateUser.on('error', callback);
updateUser.end(JSON.stringify(user));
requestUser.on('error', callback);