【问题标题】:Unqiue usernames in firebase with no work aroundsfirebase 中唯一的用户名,没有变通办法
【发布时间】:2021-11-19 04:39:05
【问题描述】:

我看过其他答案,但我仍然感到困惑。基本上我有一个 firebase 身份验证系统,并且正在尝试强制使用唯一的用户名。

到目前为止,我有 2 个集合,一个 users 集合和一个 username 集合。在用户集合中,文档包含用户信息。在 usernames 集合中,每个文档 id 是用户名,在文档中是 userId。

为了防止用户注册时出现重复的用户名,我正在考虑对用户名集合进行查询并检查用户名是否存在,从那里向用户显示错误或继续注册。

代码:

// Check if user exists

const usernamesRef = collection(db, 'usernames');
const usernameExists = query(usernamesRef, where('usernames', '==', username));

if(usernameExists) {
  // handle error
} else {
  createUserWithEmailAndPassword(auth, email, password)
  //
}

我的问题是有什么办法可以规避这个问题,或者有没有更好的方法来做到这一点。我以前从未做过这样的事情,所以我正在寻找输入/建议。谢谢。

【问题讨论】:

    标签: reactjs firebase react-native google-cloud-firestore firebase-security


    【解决方案1】:

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 2016-05-16
    相关资源
    最近更新 更多