angular - 如何获取和更新用户属性 AWS amplify angular 6
问题描述
注册到应用程序后如何更改 Cognito 用户的属性?应该使用什么 API 来获取用户的详细信息,例如名字、姓氏等?应该使用什么 API 来更新用户详细信息?
解决方案
要获取用户的详细信息,只需使用this.amplifyService.auth().currentAuthenticatedUser()
和检索user.attributes
字段。
/**
* Get current authenticated user
* @return - A promise resolves to curret authenticated CognitoUser if success
*/
currentAuthenticatedUser(): Promise<CognitoUser | any>;
要更新属性,请使用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
示例进行操作:
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-cli - 使用 AWS CLI 以编程方式从 AWS 区域获取 AWS Route 53 托管区域 ID
- html -
, 标签在 html5 中已过期,但是当我使用它们时,它们可以正常工作吗? - sql - 用于分组事务的数据库模式模式
- node.js - Sequelize 无法访问 GCP Cloud SQL
- reactjs - 从 mongodb 中匹配此值的文档数组中删除许多项目
- javascript - Vue v-if不隐藏移动标题
- javascript - 从 obj 匹配时无法形成结构和更新标志值
- android - 横幅广告未显示真实单位 ID
- ruby-on-rails - Rails 6,切换Git分支后架构文件与迁移文件不匹配
- testing - Testcafe:您要切换到的 iframe 的内容未加载