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

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

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

最佳答案

收件人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));

关于angular - 如何获取和更新用户属性 AWS amplify angular 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53653219/

相关文章:

javascript - 正则表达式替换非数字

postgresql - Amazon Aurora PostgreSQL 选择进入 OUTFILE S3

php - 使用 PHP 的 Http 身份验证不起作用

sql-server - UNC 路径和 Windows 身份验证的批量插入错误

Angular 2 RC6 : cli-compiler says "function calls are not supported"

javascript - Angular 8 在异步调用链之后返回可观察的

amazon-web-services - 通过 aws-cdk 的 VPC 对等互连

python - 从 lambda 函数内访问 AWS API?

web-services - Codeigniter 网络服务

javascript - routerLink 使用参数进行路由不起作用