Muhammad Ali
11/02/2021, 3:00 AMsign-in
request, I want to add some basic info for user so that their home screen can be rendered. was thinking to return this info as part of sign in request and inject it using some cognito trigger.
I setup these triggers
const auth = new sst.Auth(this, "Auth", {
cognito: {
userPool: userPool,
userPoolClient: userPoolclient,
triggers: {
postAuthentication: "src/lambdas/cognito.postAuthentication",
preTokenGeneration: "src/lambdas/cognito.preTokenGeneration",
preAuthentication: "src/lambdas/cognito.preAuthentication",
},
},
});
and when i do aws cognito-idp sign-up
-> aws cognito-idp admin-confirm-sign-up
-> aws cognito-idp initiate-auth
... none of these triggers get triggered. The code for trigger look like this
export const preTokenGeneration: APIGatewayProxyHandlerV2 = async (event) => {
console.log(event);
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `This is from preTokenGeneration ${event.requestContext.time}.`,
};
};
Slawomir Stec
11/02/2021, 3:14 AMSlawomir Stec
11/02/2021, 3:14 AMSlawomir Stec
11/02/2021, 3:14 AMSlawomir Stec
11/02/2021, 3:14 AMimport {
PostAuthenticationTriggerEvent,
PostAuthenticationTriggerHandler
} from 'aws-lambda/trigger/cognito-user-pool-trigger/post-authentication'
export const handler: PostAuthenticationTriggerHandler = async (
event: PostAuthenticationTriggerEvent
) => {
await console.log(event)
return event
}
Slawomir Stec
11/02/2021, 3:14 AMMuhammad Ali
11/02/2021, 3:15 AMtriggers
section?Slawomir Stec
11/02/2021, 3:16 AMSlawomir Stec
11/02/2021, 3:16 AMconst postAuthenticationLambda = new Function(this, 'PostHandlerLambda', {
handler: 'src/postAuthentication.handler'
})
props.userPool = new UserPool(this, 'TestUserPool', {
userPoolName: 'TestUserPool',
signInAliases: { email: true, phone: false, username: true },
selfSignUpEnabled: true,
removalPolicy: RemovalPolicy.DESTROY,
lambdaTriggers: {
postAuthentication: postAuthenticationLambda,
preSignUp: preSignupLambda
},
standardAttributes: {
email: {
required: true,
mutable: true
}
}
})
Slawomir Stec
11/02/2021, 3:17 AMSlawomir Stec
11/02/2021, 3:18 AMMuhammad Ali
11/02/2021, 3:33 AMuserPool
and not the sst.Auth
function. Here is example
const userPool = new cognito.UserPool(this, 'UserPool', {
selfSignUpEnabled: true,
signInAliases: {email: true},
signInCaseSensitive: false,
lambdaTriggers:{
postAuthentication: new sst.Function(this, 'PostAuthentication', {
handler: "src/lambdas/cognito.postAuthentication"
}),
...
});
I also changed my triggers to what you suggestedFrank
const auth = new sst.Auth(this, "Auth", {
cognito: {
userPool: userPool,
Where is userPool
coming from?