Describe the bug
According to docs at: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html a clientMetadata provided to Auth.signUp method should be available in post confirmation lambda. Unfortunately it's not. (there's no clientMetadata key in request)
To Reproduce
Steps to reproduce the behavior:
Auth.signUp with clientMetadataconst result = await Auth.signUp({
username: "username",
password: "P@ssw0rd",
attributes: {
given_name: "givenname",
family_name: "lastname",
email: "email"
},
clientMetadata: {
"foo": "bar",
}
});
exports.handler = async (event, context, callback) => {
console.log(event);
console.log(event.request.clientMetadata ? "It's fine" : "There's no clientMetadata");
}
**Expected behavior**
I'd expect that clientMetadata passed to `Auth.signUp` method is available in post confirmation lambda as above docs states.
<details>
<summary><strong>Environment</strong></summary>
<!-- Please run the following command inside your project and copy/paste the output into the codeblock: -->
npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages
```
System:
OS: Windows 10 10.0.18362
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 10.20 GB / 31.72 GB
Binaries:
Node: 12.13.0 - C:Program Filesnodejsnode.EXE
Yarn: 1.19.0 - C:Program Files (x86)Yarnbinyarn.CMD
npm: 6.12.0 - C:Program Filesnodejsnpm.CMD
Browsers:
Edge: 44.18362.449.0
Internet Explorer: 11.0.18362.1
npmPackages:
aws-amplify: ^1.2.4 => 1.2.4
aws-amplify-react: ^2.5.4 => 2.5.4
react: ^16.12.0 => 16.12.0
react-dom: ^16.12.0 => 16.12.0
react-router-dom: ^5.1.2 => 5.1.2
react-scripts: 3.2.0 => 3.2.0
typescript: 3.7.2 => 3.7.2
@krlm The signUp and confirmSignUp methods and their associated flows in the Cognito service are distinct. ConfirmSignUp is used to pass a confirmation code (typically sent via SMS or email) back to Cognito to mark the user as 'Confirmed'. Only signUp Lambda trigger is called by the signUp method.
@haverchuck Sorry, but it's not what the documentation says about clientMetadata parameter: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html#cognito-user-pools-lambda-trigger-syntax-post-confirmation-request
You can pass this data to your Lambda function by using the ClientMetadata parameter in the following API actions: AdminConfirmSignUp, ConfirmForgotPassword, ConfirmSignUp, and SignUp.
It explicitly mentions sign up action, so I'd argue that it should be possible or the documentation has to be fixed.
@krlm The paragraph you've quoted is true - you can pass client metadata to the triggers that are called by those API actions.
However, what you've described is a case in which you are expecting to see clientMetadata getting passed from the SignUp API action to the Post Confirmation trigger. This won't happen, since the SignUp API action does not call the Post Confirmation trigger. The ConfirmSignUp API action is what calls the Post Confirmation trigger. If you want to get data to the Post Confirmation trigger, you will need to pass it to Auth.confirmSignUp (as part of the options parameter).
@haverchuck Sorry if I misunderstand something, but the documentation is not about arbitrary lambda from the workflow. It's specific about Post Confirmation Lambda and Post Confirmation Request Parameters and explicitly says that clientMetadata parameter can be passed by the SingUp action.
I understand that it might not work, but then you should remove SignUp from the actions mentioned in that paragraph.
@krlm I am working on getting clarification from the Cognito team.
@krlm I have spoken to the Cognito team. My understanding is that if your SignUp trigger uses the API to mark the user as confirmed, THEN the client metadata that was passed to the SignUp trigger will be passed directly to the PostConfirmation trigger (so it's kind of a specialized use case). In other cases, you will need to pass the clientMetadata through the Auth.confirmSignUp method.
@haverchuck You mean Pre Sign-up trigger with autoConfirmUser parameter? Then, I think, it should be clarified in the cited docs, otherwise it's grossly misleading.
@krlm Apologies- the _Pre_ SignUp trigger is indeed what I meant. I am going to close this issue for now since it isn't Amplify-related, but I am filing a ticket with Cognito to address the documentation issue.
@haverchuck This issue seems to have not been addressed. Are there any updates from the cognito auth team?
@krlm Did you ever get this to work?
I am calling Auth.signUp with clientMetaData as a parameter, and setting event.response.autoConfirmUser to true inside of the Pre Sign-up lambda. When I check the logs for the Pre Sign-up lambda clientMetaData is present inside of event.request but then when I check the Post Confirmation lambda clientMetaData is missing.
The documentation still says clientMetadata can be passed to the Post Confirmation lambda using Auth.signUp and doesn't give any special instructions for how to do that which would lead me to believe it should just work.
@daallen303 no, they were supposed to fix the docs.
@haverchuck This issue seems to have not been addressed. Are there any updates from the cognito auth team?
@krlm Did you ever get this to work?I am calling
Auth.signUpwithclientMetaDataas a parameter, and settingevent.response.autoConfirmUsertotrueinside of the Pre Sign-up lambda. When I check the logs for the Pre Sign-up lambdaclientMetaDatais present inside ofevent.requestbut then when I check the Post Confirmation lambdaclientMetaDatais missing.The documentation still says
clientMetadatacan be passed to the Post Confirmation lambda usingAuth.signUpand doesn't give any special instructions for how to do that which would lead me to believe it should just work.
I'm doing this same thing, but in my Pre Sign-up lambda, clientMetadata is not even in the request. validationData is, but it's null.
I'm doing this same thing, but in my Pre Sign-up lambda, clientMetadata is not even in the request. validationData is, but it's null.
@nicolasheady Are you sure you're doing exactly as @krlm does in the first post? I tried the same code below and my pre sign-up lambda receives the clientMetadata in the request just fine;
const result = await Auth.signUp({
username: "username",
password: "P@ssw0rd",
attributes: {
given_name: "givenname",
family_name: "lastname",
email: "email"
},
clientMetadata: {
"foo": "bar",
}
});
Most helpful comment
@krlm The paragraph you've quoted is true - you can pass client metadata to the triggers that are called by those API actions.
However, what you've described is a case in which you are expecting to see clientMetadata getting passed from the SignUp API action to the Post Confirmation trigger. This won't happen, since the SignUp API action does not call the Post Confirmation trigger. The ConfirmSignUp API action is what calls the Post Confirmation trigger. If you want to get data to the Post Confirmation trigger, you will need to pass it to Auth.confirmSignUp (as part of the options parameter).