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
TypeScript definition not matching: Property 'attributes' does not exist on type 'CognitoUser' #9941
Comments
Hi @mcanvar , appreciate you submitting this issue, with the great level of details to relocate it. Our team will investigate this and get back to you! |
Thank you for your help @abdallahshaban557 |
This way you can have type support when reading user attributes, async function showUserInfo() {
const user = await Auth.currentAuthenticatedUser();
const userAttributes = await Auth.userAttributes(user); // CognitoUserAttribute[] type
} |
Thanks @elorzafe, I know the |
@mcanvar I didnt follow, you mean getting those statically without a method (async) |
@elorzafe Facing a similar problem, the issue is that from the linked thread: "currentAuthenticatedUser" returns a "CognitoUser" which is missing the public field "attributes" in its type definition, the following should be valid: const user = await Auth.currentAuthenticatedUser();
console.log(user.attributes) |
Maybe something to note: As I have noticed, when any of the signIn or confirmSignIn functions is used, the object returned from the response is one without attributes. Only if you use currentAuthenticatedUser you get an object with attributes. While I'm not sure if this is intentional or not, it could explain why the typing is missing the attributes as it isn't always included in successful responses. |
My workaround for username + attributes is: |
I have another workaround. I'm not sure if it's a good Idea ...
|
We have published an RFC on our plan for improving TypeScript support in Amplify JS & would love to get your feedback & suggestions! |
The developer preview for v6 of Amplify has officially been released with improvements to TypeScript support and much more! Please check out our announcement and updated documentation to see what has changed. This issue should be resolved within the dev preview and upcoming General Availability for Amplify v6, but let us know with a comment if there are further issues. |
With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved and we highly recommend updating to the most recent version. Please refer to our release announcement, migration guide, and documentation for more information. |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
@abdallahshaban557 asked me to open a new issube because the old one(#4927) closed I guess.
For example we set the signed in user from a context by using
Auth.currentAuthenticatedUser()
and then set the user on context state, when we get the user on a next page like so:Unfortunatelly TS turns red under
attributes
:TS2339: Property 'attributes' does not exist on type 'CognitoUser'.
Expected behavior
TS shouldn't throw error, type should be corrected
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: