Skip to content
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

add sample codes for Auth.deleteUserAttributes in JS #3413

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ async function updateUser() {
}
```

You can also use the `deleteUserAttributes` method of the __Auth__ class to delete user attributes:

```js
async function updateUser() {
const user = await Auth.currentAuthenticatedUser();
await Auth.deleteUserAttributes(user, ['address']);
}
```

### Reading user attributes

To read user attributes, you can use the `currentAuthenticatedUser` method of the Auth class:
Expand Down Expand Up @@ -107,4 +116,15 @@ async function updateUser() {
'custom:favorite_ice_cream': 'vanilla'
});
}
```

You can also use the `deleteUserAttributes` method of the __Auth__ class to delete custom user attributes:

```js
async function updateUser() {
const user = await Auth.currentAuthenticatedUser();
await Auth.deleteUserAttributes(user, [
'custom:favorite_ice_cream'
]);
}
```
11 changes: 11 additions & 0 deletions docs/lib/auth/fragments/js/manageusers.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ let result = await Auth.updateUserAttributes(user, {
console.log(result); // SUCCESS
```

You can delete user attributes:

```javascript
let user = await Auth.currentAuthenticatedUser();

let result = await Auth.deleteUserAttributes(user, [
'family_name'
]);
console.log(result); // SUCCESS
```

> You can find a <a href="https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#cognito-user-pools-standard-attributes" target="_blank">list of all custom attributes here</a>.

If you change the email address, the user will receive a confirmation code. In your app, you can confirm the verification code:
Expand Down