Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
queryHandler: async (event,context) => {
const payload = JSON.parse(event.body);
const documentClient = new DynamoDB.DocumentClient({
region : process.env.REGION
});
try {
switch(payload.action){
case 'expectauth':
const expires_at = parseInt(new Date().getTime() / 1000) + 300;
await documentClient.put({
TableName : process.env.DYNAMODB_TABLE,
Item: {
authkey : payload.authkey,
connectionId : event.requestContext.connectionId,
username : payload.username,
expires_at : expires_at,
authVerified: false
}
}).promise();
return {
statusCode: 200,
body : "OK"
};
case 'getconid':
return {
statusCode: 200,
body: `connectionid:${event.requestContext.connectionId}`
};
case 'verifyauth':
const data = await documentClient.get({
TableName : process.env.DYNAMODB_TABLE,
Key : {
authkey : payload.authkey
}
}).promise();
if(!("Item" in data)){
throw "Failed to query data";
}
if(data.Item.authVerified === true){
return {
statusCode: 200,
body: `authverified:${payload.challengeText}`
}
}
throw "auth verification failed";
}
} catch (error) {
console.log(error);
}
return {
statusCode: 200,
body : "ok"
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment