Krush
Krush

Reputation: 27

Allow users to update their own AWS Cognito attributes

What are the options for implementing a React interface to allow users to update their own attributes like name, address and phone number? Is this something I'd need to completely custom build with Amplify?

I would expect a self-service account update feature to be pretty standard, like the sign-up, sign-on and password reset features of the Cognito hosted UI. But I can't seem to find any documentation or articles about it.

Upvotes: 0

Views: 1106

Answers (1)

Dave
Dave

Reputation: 7717

It is standard enough that you'll find many templates online, but not so standard that you'll get it out of the box (like you do with login, create-account, forgot-password). Build the UI yourself, then 'save' updates using the updateUserAttributes method on Amplify's Auth class.

import { Auth } from 'aws-amplify'

async function updateUser() {
  const user = await Auth.currentAuthenticatedUser();
  await Auth.updateUserAttributes(user, {
    'address': '105 Main St. New York, NY 10001'
  });
}

Here's a link to the Amplify documentation for updateUserAttributes.

Upvotes: 2

Related Questions