How do I check if the username is already in use?

few days ago @TIMAI2 helped me with saving data to firebase, and for another app I'm making I changed it so now it saved user number, username and their password. It all works great, but I have no idea how to check if the username is already in use, any ideas on how to do it?


You have a few choices, here are a couple:

  1. When a user signs up, in addition to their Users> sign up data, save their username to another node, e.g. gameUsers. (this is known in firebase as denormalising, and is quite normal and accepted practice, even though it seems repetitive) You can then call back this node and test any new user name entered before it is submitted.

  2. In your firebase rules, set up an index for "Username". You can then submit a query via a web component (REST api) to return all the usernames in a list.

Thanks, I used the first method.
But what do I do in the app inventor to search all the usernames from here and tell if there is one like the one I put already existing? Can you show me the blocks please?

It should be straightforward:

  1. Call getValue on the tag All_Usernames
    (Now easiest way...)
  2. When you get the tag, set the value to a variable
  3. Use the text "contains" block to test the new entered username against the variable (values returned)

If you want to be more specific, you can convert the returned value to a list, then iterate over the list, testing each item for a match


Textbox1 is for the user tag e.g. user01, user02, textbox2 is for the username

Thanks a lot, it works, but it still puts you in even if the username already exists. text is shown but it still saves your username and password, it's 100% cause of a misplacement. Do you know where to put it?

(I put it below the orange bit "initalize global userNumber" and it doesn't work properly here)

Look at my example again. it needs the value from the tag "All-Usernames", you are supplying a different tag/value. You will need to put in an if/elseif to test the tag that is returned by getValue...

Is this what you mean?
Cause it doesn't work when I do it that way :confused:

You will need to make sure you have your workflow running correctly, with your blocks in the correct places.

  1. New user submits their username/password
  2. Fetch the list if usernames from firebase
  3. Check the new username against the returned list
  4. If new username is in the list, then return the new user to the sign up form
  5. If the new username is not in the list THEN submit their sign up details to Firebase, do what ever else it is you need to do with that new user

I did not test out my blocks, you therefore may need to check what is coming back from Firebase when you call the All_Usernames tag, and that the test is working for you.

Still can't understand it. What do I do can you show me blocks?

This is the best I can suggest from your blocks: