如何获取和更新用户属性AWS Amplify Angle 6 [英] How to get and update user attributes AWS amplify angular 6

查看:205
本文介绍了如何获取和更新用户属性AWS Amplify Angle 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How would I change the attributes of the Cognito user after sign up into the application? What API should be used to fetch the details of the user like First Name, Last Name etc? What API should be used to update the user details?

推荐答案

获取用户的详细信息,只需使用this.amplifyService.auth().currentAuthenticatedUser()并检索user.attributes字段即可.

To fetch the details of the user, simply use this.amplifyService.auth().currentAuthenticatedUser() and retrieve the user.attributes fields.

/**
 * 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示例:

If you need to retrieve the CognitoUser, you can follow the Change password example of the documentation :

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 Angle 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆