awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.3k stars 335 forks source link

VerifyAuthChallengeResponse Cognito event fails to deserialize when response.answerCorrect is null #825

Closed mawallace closed 6 months ago

mawallace commented 6 months ago

I wrote a set of Cognito Lambda triggers for a custom auth flow, using the event types provided in this library. When using the auth flow in a web app, I encountered the following error:

VerifyAuthChallengeResponse failed with error failed to deserialize the incoming data into the function's payload type: [response.answerCorrect] response.answerCorrect: invalid type: null, expected a boolean at line 1 column 582
.
AmplifyError@http://localhost:3000/static/js/bundle.js:68099:10
AuthError@http://localhost:3000/static/js/bundle.js:60434:10
@http://localhost:3000/static/js/bundle.js:62959:77

It seems like the Cognito is sending an event for the VerifyAuthChallengeResponse trigger with response.answerCorrect explicitly set to null (not just missing).

I patched in this repository and added deserialize_nullish_boolean (which is used for other fields in the module) to the answer_correct field, like below:

/// `CognitoEventUserPoolsVerifyAuthChallengeResponse` defines verify auth challenge response parameters
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CognitoEventUserPoolsVerifyAuthChallengeResponse {
    #[serde(default, deserialize_with = "deserialize_nullish_boolean")]
    pub answer_correct: bool,
}

This resolved the issue.

If this makes sense to the maintainers, I'm happy to submit a pull request with this change.

calavera commented 6 months ago

Thanks for diving into that. Yes please, open a Pull Request, we really appreciate all these improvements to the event types.

mawallace commented 6 months ago

Fixed by #826.

github-actions[bot] commented 6 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one.