![](/img/trans.png)
[英]Cognito user update attribute getting error - Error: User is not authenticated
[英]Error: User is not authenticated amazon cognito in nodejs
我正在使用amazon-Cognito-identity-js
和aws-sdk
在我的 nodeJs 应用程序中设置身份验证。
首先,我根据文档使用userpool.signUp(..)
方法注册。 然后我根据文档使用cognitoUser.confirmRegistration(..)
方法确认了验证码。
到这里为止,一切正常。 但是,现在我想获取用户的所有属性。 我找到了一个可以给我属性的方法cognitoUser.getUserAttributes(..)
。 但是当我在cognitoUser.confirmRegistration(..)
之后调用此方法时,它会返回Error: User is not authenticated 。
我经历了一个 SO 问题,在那里我得到了
getCurrentUser()
will return null at backend side。
那么,我如何使用 nodejs 在完全安全的后端授权任何用户?
您必须先调用authenticateUser
方法:
import { CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js'
const authUser = () => {
const cognitoUser = new CognitoUser({ Username, Pool })
const authDetails = new AuthenticationDetails({
Username,
Password,
})
cognitoUser.authenticateUser(authDetails, {
onSuccess: () => {
console.log("User authenticated")
},
onFailure: (error) => {
console.log("An error happened")
},
})
}
之后, getCurrentUser
方法将返回当前登录的用户。 您还可以调用getUserAttributes
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.