Search code examples
amazon-web-servicesamazon-cognitoaws-amplify

How to use AWS amplify securely


I'm experimenting with AWS amplify. In particular, looking to provide a means for a user to change their cognito password. I don't understand how that is done in a secure fashion given the client id is exposed.

What am I missing?

Here are the docs for what I'm using....

https://github.com/aws-amplify/amplify-js/tree/main/packages/amazon-cognito-identity-js


Solution

  • Amplify uses amazon-cognito-identity-js under the hood. So use Auth module from Amplify(aws-amplify).

    import { Auth } from 'aws-amplify' 
    

    then you can let users change their password since they're already signed in and all necessary information is already in there(browser).

    const currentUser = await Auth.currentAuthenticatedUser();
    
    const currentPassword = "";
    const newPassword = "";
    
    await Auth.changePassword(
      currentUser,
      currentPassword,
      newPassword
    );