简体   繁体   English

如何在我的 flutter firebase 应用程序中检查用户名可用性

[英]How can i check username availability in my flutter firebase app

I am trying to check if a username is already taken in my flutter and firebase app, but I am facing some problems.我正在尝试检查我的 flutter 和 firebase 应用程序中是否已使用用户名,但我遇到了一些问题。 I am able to query the user's collection and compare a name string saved in the input of the text form with names already in the database, which works perfectly well.我能够查询用户的集合,并将文本表单输入中保存的名称字符串与数据库中已有的名称进行比较,效果非常好。 But my problem is when a user takes a name and that same user tries to save his profile without changing his name, he gets the message username is already taken, meaning he can't save his profile cause he has already taken his own name.但我的问题是,当一个用户取了一个名字,而同一个用户试图在不更改他的名字的情况下保存他的个人资料时,他会收到消息用户名已被使用,这意味着他无法保存他的个人资料,因为他已经取了自己的名字。 I want a solution where a user can save his profile if he or she hasn't modified his or her username without going through the username is already taken process.我想要一个解决方案,如果用户没有修改他或她的用户名而不经过用户名已经采取的过程,他或她可以保存他的个人资料。 I don't know if it's possible to add an if statement to check if the current user name is equal to the username in the text field?不知道可不可以加个if语句来判断当前用户名是否等于文本域中的用户名? or help with any solution that works.或帮助解决任何有效的问题。 please these are my codes below请这些是我下面的代码

//checks fields of user collection and compares the 
 //string _username with the userName of each user.
 final QuerySnapshot result = await Firestore.instance
      .collection('users')
      .where('userName', isEqualTo: _userName)
      .getDocuments();

    //converts results to a list of documents
  final List<DocumentSnapshot> documents = 
 result.documents;

  //checks the length of the document to see if its 
   //greater than 0 which means the username has already been taken 
   the name
if (documents.length > 0) {
    print(_userName + ' is already taken choose 
    another name');
 }else{
   print(_userName + ' are you sure you want to use 
    this name');
  }

I think a solution would to only check to see if this username is taken if the user changes his username.我认为一个解决方案是只检查如果用户更改了他的用户名,是否使用了这个用户名。 Therefore you would not have to worry if the user with the taken username is just saving his profile without changing his username.因此,您不必担心使用已使用用户名的用户只是保存他的个人资料而不更改他的用户名。

yes if you are in firestore as backend...you can not show query stream in registration page for username suggestions for availability bcoz u hav to set firestore rules insecure and allow unauthorised users to read write your database...so better to push a new page after that registration page where you can place field for username in this case you are already registered and logged in so firestore security rule will not invade.... Happy coding:)是的,如果你在 firestore 作为后端......你不能在注册页面中显示查询 stream 以获取可用性的用户名建议,因为你必须将 firestore 规则设置为不安全并允许未经授权的用户读写你的数据库......所以最好推送一个在该注册页面之后的新页面,您可以在其中放置用户名字段,在这种情况下,您已经注册并登录,因此 firestore 安全规则不会入侵....快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase:如何在应用检查中注册我的 Flutter 应用? - Firebase: How do I register my Flutter app in app check? 我如何在我的 flutter 应用程序中使用第二个 firebase 项目? - How can i user second firebase project in my flutter app? 如何在Flutter为我的Android App设置App Check? - How can I set up App Check for my Android App in Flutter? 无法获取 Firebase 应用程序的调试令牌 检查我的 Flutter iOS 应用程序 - Can't get debug token for Firebase App Check for my Flutter iOS App 我如何托管我的 flutter web 和 firebase - How can I host my flutter web with firebase 我可以使用 firebase 作为 flutter 桌面应用程序的后端吗? 如果有怎么办? - Can I use firebase as a backend for flutter desktop app? If so how? 我如何在收到背景 firebase 消息时启动 Flutter 应用程序,即使屏幕已锁定我也希望我的应用程序启动 - How i can make Flutter application start when it receives background firebase message even if the screen is locked i want my app to start 我的 flutter iOS 应用程序尚未发布。 如果应用程序尚未安装,我如何知道我的 firebase 动态链接可以打开 Appstore? - My flutter iOS app hasn't been released yet. How can I know my firebase dynamic link works to open Appstore if the app isn't installed yet? Flutter - firebase_app_check 在发布模式下不工作,如何解决? - Flutter - firebase_app_check not working in release mode, how fix it? 我的 firebase 可调用云 function 被调用了两次(当我只调用一次时),如何避免我的 flutter 应用程序失败? - My firebase callable cloud function is called twice (when I called only once), how can I avoid my flutter app from failure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM