I am trying to signup the user to the cognito when...
# help
m
I am trying to signup the user to the cognito when I send the API request to add the user to the DB, any idea how can this be done? Maybe the answer is obvious but I don't see it.
t
I would sign the user up to cognito and then user a lambda trigger from cognito to create the db record
k
Hi, heres some sample code to help. apistack.js ======== this.auth = new sst.Auth(this, "Auth", { cognito: { triggers: { customMessage: { handler: "services/cognito/customMessage.main", }, preSignUp: { handler: "services/cognito/preSignUp.main", }, // preAuthentication: { // handler: "services/cognito/preAuthentication.main", _// // environment: { TABLE_NAME: props.table.tableName },_ // // permissions: [table], // }, postConfirmation: { handler: "services/cognito/postConfirmation.main", environment: { TABLE_NAME: props.table.tableName }, permissions: [table], }, }, custommessage.js ============== export const main = (event, context, callback) => { if(event.triggerSource === "CustomMessage_SignUp") { // Ensure that your message contains event.request.codeParameter. This is the placeholder for code that will be sent event.response.smsMessage = "Welcome to the service. Your confirmation code is " + event.request.codeParameter; event.response.emailSubject = "Welcome to the service"; event.response.emailMessage = "Thank you for signing up. " + event.request.codeParameter + " is your verification code"; } // Return to Amazon Cognito callback(null, event); }; I use the preSignup and postConfirmation. inside the postConfirmation i add the user to a separate DB table
m
I did it already, thank you guys