【问题标题】:How to get and update user attributes AWS amplify angular 6如何获取和更新用户属性 AWS amplify angular 6
【发布时间】:2019-05-08 06:10:25
【问题描述】:

注册到应用程序后如何更改 Cognito 用户的属性?应该使用什么 API 来获取用户的详细信息,例如名字、姓氏等? 应该使用什么 API 来更新用户详细信息?

【问题讨论】:

    标签: angular amazon-web-services authentication amazon-cognito aws-amplify


    【解决方案1】:

    对于fetch the details of the user,只需使用this.amplifyService.auth().currentAuthenticatedUser() 并检索user.attributes 字段。

    /**
     * Get current authenticated user
     * @return - A promise resolves to curret authenticated CognitoUser if success
     */
    currentAuthenticatedUser(): Promise<CognitoUser | any>;
    

    update the attributes,使用updateUserAttributes方法。

    /**
     * Update an authenticated users' attributes
     * @param {CognitoUser} - The currently logged in user object
     * @return {Promise}
     **/
    updateUserAttributes(user: CognitoUser | any, attributes: object): Promise<string>;
    

    如果需要找回CognitoUser,可以按照文档的Change password example进行操作:

    import { Auth } from 'aws-amplify';
    
    Auth.currentAuthenticatedUser()
        .then(user => {
            return Auth.changePassword(user, 'oldPassword', 'newPassword');
        })
        .then(data => console.log(data))
        .catch(err => console.log(err));
    

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 2020-06-26
      • 2019-12-16
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 2019-04-10
      • 2018-01-05
      • 2021-08-20
      相关资源
      最近更新 更多