Manage user attributes
Fetch the current user's attributes
Invoke the following api to get the list of attributes assigned to the user.
1Amplify.Auth.fetchUserAttributes(2 attributes -> Log.i("AuthDemo", "User attributes = " + attributes.toString()),3 error -> Log.e("AuthDemo", "Failed to fetch user attributes.", error)4);
Update user attribute
Invoke the update api for creating new or updating existing user attributes.
To update a single user attribute, call updateUserAttribute
:
1AuthUserAttribute userEmail =2 new AuthUserAttribute(AuthUserAttributeKey.email(), "email@email.com");3Amplify.Auth.updateUserAttribute(userEmail,4 result -> Log.i("AuthDemo", "Updated user attribute = " + result.toString()),5 error -> Log.e("AuthDemo", "Failed to update user attribute.", error)6);
To update multiple user attributes at a time, call updateUserAttributes
:
1Amplify.Auth.updateUserAttributes(2 attributes, // attributes is a list of AuthUserAttribute3 result -> Log.i("AuthDemo", "Updated user attributes = " + result.toString()),4 error -> Log.e("AuthDemo", "Failed to update user attributes.", error)5);
Verify user attribute
Some attributes require confirmation for the attribute update to complete. If the attribute need to be confirmed, the result of the above api will be CONFIRM_ATTRIBUTE_WITH_CODE
. A confirmation code will be sent to the delivery medium mentioned in the delivery details. When the user gets the confirmation code, you can present a UI to the user to enter the code and invoke the confirm attribute api with their input:
1Amplify.Auth.confirmUserAttribute(AuthUserAttributeKey.email(), "344299",2 () -> Log.i("AuthDemo", "Confirmed user attribute with correct code."),3 error -> Log.e("AuthDemo", "Failed to confirm user attribute. Bad code?", error)4);
Resend verification code
If the code has expired or the user needs to resend the confirmation code, invoke the resend api as shown below:
1Amplify.Auth.resendUserAttributeConfirmationCode(AuthUserAttributeKey.email(),2 result -> Log.i("AuthDemo", "Code was sent again: " + result.toString()),3 error -> Log.e("AuthDemo", "Failed to resend code.", error)4);