如何获取和更新用户属性 AWS amplify angular 6

Posted

技术标签:

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

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

【问题讨论】:

【参考方案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));

【讨论】:

以上是关于如何获取和更新用户属性 AWS amplify angular 6的主要内容,如果未能解决你的问题,请参考以下文章

属性更新后更新用户上下文 - AWS Amplify

Swift - AWS Cognito 使用 Amplify - 如何在 swift 登录后获取令牌?

删除 AWS Amplify 添加的用户池

Aws Amplify:部分更新(突变)

如何使用 Amplify 框架从 AWS 中的 API 获取 http 状态和详细响应?

如何使用 aws amplify 保持用户登录 react-native