Skip to content

Commit

Permalink
Merge branch 'cepdnaclk:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
EshanJayasundara authored Jan 27, 2024
2 parents 12f14af + faed260 commit dc31145
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions backend/serverless/Lambda/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ const AWS = require('aws-sdk');
const cognito = new AWS.CognitoIdentityServiceProvider();
const { DynamoDBClient, PutItemCommand } = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient()

const lambda = new AWS.Lambda();

exports.handler = async (event, context, callback) => {
try {


const requestBody = JSON.parse(event.body);
const email = requestBody.email;
// console.log(event);
// console.log(event.body);
// console.log(email);
// console.log(JSON.stringify(requestBody.email));
const password = requestBody.password;
const gunid = requestBody.gunid;
const gloveid = requestBody.gloveid;
const headsetid = requestBody.headsetid;

// Add user to Cognito User Pool
const signUpParams = {
Expand All @@ -32,6 +26,26 @@ exports.handler = async (event, context, callback) => {
]
};

//invoke qr generate and store in s3
const qrdata = {"email": email}
const qrinput = {
FunctionName: "qrstore",
InvocationType: "RequestResponse",
Payload: JSON.stringify(qrdata)
};

lambda.invoke(qrinput, (err, data) => {
if (err) {
console.error(err);
} else {
console.log('Lambda Invocation Response:', data);
return {
statusCode: 500,
body: {"msg":JSON.stringify('Internal Server Error')}
};
}
});

const signUpResponse = await cognito.signUp(signUpParams).promise();

// Add user to DynamoDBUser model
Expand All @@ -41,8 +55,6 @@ exports.handler = async (event, context, callback) => {
//"UserId": signUpResponse.UserSub, // Use the Cognito User Sub as the DynamoDB key
"email": {"S": email},
"gunid": {"S": gunid},
"gloveid": {"S": gloveid},
"headsetid": {"S": headsetid},

}
};
Expand All @@ -56,13 +68,17 @@ exports.handler = async (event, context, callback) => {

}
};


//add to user db
const commandUser = new PutItemCommand(dynamoDBParamsUser);
const responsedbUser = await client.send(commandUser);

const commandEnv = new PutItemCommand(dynamoDBParamsEnv);
const responsedbEnv = await client.send(commandEnv);




// Return a response
const response = {
Expand Down

0 comments on commit dc31145

Please sign in to comment.