-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(@aws-amplify/auth): define validationData type as object literal #8045
fix(@aws-amplify/auth): define validationData type as object literal #8045
Conversation
Codecov Report
@@ Coverage Diff @@
## main #8045 +/- ##
==========================================
+ Coverage 75.42% 75.44% +0.02%
==========================================
Files 215 215
Lines 13548 13548
Branches 2673 2673
==========================================
+ Hits 10218 10221 +3
+ Misses 3127 3124 -3
Partials 203 203
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM 👍
…in SignUpParams type
…karocho/amplify-js into auth-validationData-type-fix
… auth-validationData-type-fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
Looking at https://github.com/aws-amplify/amplify-js/blob/main/packages/auth/src/Auth.ts#L326 I think the intended usage of The current type validationData: [
new CognitoUserAttribute({Name: 'foo', Value: 'bar'})
] but the implementation will throw a SerializationException as runtime error. I would rather prefer a typescript error at compile time than a runtime error when a user is using my project. |
This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Description of changes
validationData
ts-jest
linting errors when runningyarn test
validationData
to theAuth.signUp
methodIn JavaScript, users can simply pass
validationData
as an object literal with'key': 'value'
pairs, but in TypeScript we get the following error:This is because the
SignUpParams
interface was definingvalidationData
as an array of objects (viaICognitoUserAttributeData[]
).This fixes the problem for TypeScript users, but we will still need to update the documentation around any reference of
validationData
to make sure users are just passing object literals rather than an array of objects.Issue #, if available
#7774
Description of how you validated changes
I made a sample app from scratch, imported Amplify (@latest), imported Auth (@latest), manually called
Auth.signUp
, and passed different sets ofvalidationData
.We do see
"SerializationException"
errors from the server response when passing the values asintegers
(i.e."NUMBER_VALUE can not be converted to a String"
),arrays
(i.e."Start of list found where not expected"
, andobjects
(i.e. "Start of structure or map found where not expected."), so maybe it would be better to define the type as:validationData?: { [key: string]: string };
.I also wrote a new test as well to validate the type passed as a param matches what we expect from TypeScript - thanks to @iartemiev's recent updates, these types are now being explicitly checked in the
auth
testing suites.Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.