AWS Amplify-禁用当前用户帐户

时间:2018-07-05 11:45:39

标签: amazon-web-services aws-cognito aws-amplify

AWS Amplify Authentication module有一些操作方法,例如登录,注册,忘记密码等。甚至可以让用户通过以下方式更新他/她的信息:

import { Auth } from 'aws-amplify'

// Auth API Sign-in sample
Auth.signIn(username, password)
    .then(user => console.log(user))
    .catch(err => console.log(err))

// Auth API Change info sample
let result = await Auth.updateUserAttributes(user, {
    'email': 'me@anotherdomain.com',
    'family_name': 'Lastname'
})

但是,我仍然看不到要禁用(请注意,不删除)帐户。

因此,用户可以注册Web应用程序,但不能使用AWS Amplify 停用它吗?如果不是,是否还有其他方法可通过Javascript代码禁用AWS Cognito用户池用户?

1 个答案:

答案 0 :(得分:1)

我仔细阅读了Cognito用户池API的AWS文档,发现了一些方法,这些方法可以让具有管理员权限的功能禁用(而不是删除)Cognito用户池帐户!

以下是AWS网站上文档的链接: https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminDisableUser.html

还有一种重新启用用户的方法: https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminEnableUser.html

可在此处找到javascript实现: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#adminDisableUser-property

使用适用于JS的AWS开发工具包,代码将如下所示:

var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});

var params = {
  UserPoolId: 'STRING_VALUE', /* required */
  Username: 'STRING_VALUE' /* required */
};
cognitoidentityserviceprovider.adminDisableUser(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});