Sar*_*ath 3 authentication amazon-web-services amazon-cognito angular aws-amplify
注册应用程序后,如何更改 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>;
Run Code Online (Sandbox Code Playgroud)
要更新属性,请使用updateUserAttributes方法。
/**
* Update an authenticated users' attributes
* @param {CognitoUser} - The currently logged in user object
* @return {Promise}
**/
updateUserAttributes(user: CognitoUser | any, attributes: object): Promise<string>;
Run Code Online (Sandbox Code Playgroud)
如果您需要检索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));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7054 次 |
| 最近记录: |