仅在第一次登录时出现的表单

问题描述 投票:0回答:1

我正在使用React和AWS Amplify库为我的项目注册并执行Auth。现在我想创建一个只出现一次的表单(用户将额外的数据添加到数据库,例如地址),它应该出现在用户第一次注册和签名时,之后再也不会出现。我一直无法弄清楚如何做到这一点,尤其是设置条件,它只出现在第一次登录时。任何帮助将非常感激。谢谢!

reactjs amazon-cognito aws-amplify
1个回答
0
投票

你必须使用几条路径。

我假设您希望用户存储的信息将是Cognito用户池中的用户属性或单独的数据库中的用户属性。我假设您将使用UserAttributes作为答案。

只显示一次(我假设您的意思是登录,用户可以通过其他方式访问):

  1. 当用户第一次看到表单时,使用名为seenForm(或其他)的属性更新其配置文件。
  2. 在用户登录时检查用户是否具有该属性 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() }

如果该属性存在,请跳过显示该表单。否则,设置属性并显示表单。

如果用户使用其他设备登录,这种方式比使用本地存储更好。

© www.soinside.com 2019 - 2024. All rights reserved.