我正在使用React和AWS Amplify库为我的项目注册并执行Auth。现在我想创建一个只出现一次的表单(用户将额外的数据添加到数据库,例如地址),它应该出现在用户第一次注册和签名时,之后再也不会出现。我一直无法弄清楚如何做到这一点,尤其是设置条件,它只出现在第一次登录时。任何帮助将非常感激。谢谢!
你必须使用几条路径。
我假设您希望用户存储的信息将是Cognito用户池中的用户属性或单独的数据库中的用户属性。我假设您将使用UserAttributes作为答案。
只显示一次(我假设您的意思是登录,用户可以通过其他方式访问):
showForm = async() => {
await Auth.updateUserAttributes({ // this sets the seenform attribute in the user's profile to make sure that they are not shown it again
seenForm: true
})
...
}
checkUserAttributes = async () => {
await Auth.userAttributes()
.then(async (userAttributes) => {
// check to see if the attribute field exists
!userAttributes['seenForm'] ? this.showForm() : null
}
}
async componentDidMount() {
checkUserAttributes()
}
如果该属性存在,请跳过显示该表单。否则,设置属性并显示表单。
如果用户使用其他设备登录,这种方式比使用本地存储更好。