Reputation: 171
We have a React client that uses AWS Cognito and Amplify ("aws-amplify": "1.1.40").
When a user logs in we want to send some additional data to Cognito, to be used by a "pre token generation" trigger. We do this by adding a clientMetadata ({"metadataKey1": "metadataValue1"}) object to the Auth.signIn function call:
Auth.signIn(auth.email, auth.password, {"metadataKey1": "metadataValue1"})
.then(response => {
// Sign in OK
})
.catch(error => {
// Something went wrong
});
This works as expected, and the Cognito "pre token generation" lambda can extract the "metadataKey1"
from the clientMetadata in the request.
This is where our problem starts:
After the successful signIn, AWS Amplify automatically does a session refresh. This session refresh is not explicitly done by our code, and the clientMetadata object used during signIn is not set. This of course means that the automatic session refresh request to Cognito does not contain the clientMetadata, which in turn means that the Cognito "pre token generation" lambda can not extract "metadataKey1"
from the clientMetadata in the request (as it does not exist).
We have debugged the code, and found that the automatic request to Cognito happens in @aws-amplify\auth\node_modules\amazon-cognito-identity-js\es\CognitoUser.js#1249
, CognitoUser.prototype.refreshSession
. The refreshSession function can receive a clientMetadata object, but when debugging the code the clientMetadata object is always undefined
(which makes sense; we have not set it explicitly and the Amplify code does not seem to store/use the clientMetadata we set during signIn).
What we need help with:
Would really appreciate any help with this!
Upvotes: 17
Views: 5943
Reputation: 1519
According to API Reference, The ClientMetadata
value is passed as input to the functions for ONLY the following triggers:
Upvotes: 2