0

My problem is how to avoid duplication of username in xamarin using firebase.

My expected output is upon tapping the username field, if in the database, "usernametest123" is already in there and a new customer upon his/her creating account to my app, and enter a username "usernametest123", a toast will appear like "Username is already exist". I tried this way; my code behind. `

 async public void CreateAccount_Clicked(System.Object sender, System.EventArgs e)
{
try{
//thats how I declare some variable up to my 11 input fields
 string FName = textfield_Firstname.Text;
 if (string.IsNullOrEmpty(FName )){await this.DisplayToastAsync("Please Enter your first name", 1500);}
//up to 11 input fields also

                CUSTOMER customer = new CUSTOMER();
                customer.CustomerFName = FName;
                var Savedata = await customerRepo.Save(customer);
}
catch(Exception ex){
if(ex.Message.Contains("USERNAME_EXISTS"))
                {
                    await this.DisplayToastAsync("Username already Exist", 1500);
                }
                else
                {
                    await this.DisplayToastAsync(ex.Message,1500);
                }
}




}

` any link that will posted about my concern will be appreciated thank you so much

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Are you asking how to configure firebase to prevent duplicates? – Jason Dec 06 '22 at 12:13
  • hmm maybe I think sir. Cause Im still beginner to firebase, I didnt know that thing. aside to configuration sir, there's a way in code behind to address my concern? – helloFriend Dec 06 '22 at 12:39
  • its just like this, If you will use my app, assume you are CUSTOMER#1, you will create an account, so in create page you will input your infos like firstname and lastname and so on, also you will input username. When you tap the username input field and type (for exmple), jason123. Assume "jason123" is already in firebase db because CUSTOMER#2 already use it, so you will enter another username. – helloFriend Dec 06 '22 at 12:45
  • 1
    query the db to see if the name already exists before you attempt to save it – Jason Dec 06 '22 at 13:36
  • aah okay sir, do you have any link that you can recommend? so that I can study about it. – helloFriend Dec 06 '22 at 13:39
  • You can refer to the answer in the thread: ["Insert data to Firebase and set restriction to UI(username and password) in Xamarin form"](https://stackoverflow.com/questions/74587990/insert-data-to-firebase-and-set-restriction-to-uiusername-and-password-in-xama). – Zack Dec 09 '22 at 01:42
  • I tried the code in that link sir but same in the reply in the thread,I got error, like this 'FirebaseClient' does not contain a definition for 'GetCustomer' and no accessible extension method 'GetCustomer' accepting a first argument of type 'FirebaseClient' could be found (are you missing a using directive or an assembly reference?) – helloFriend Dec 09 '22 at 10:05
  • The GetCustomer method needs to be defined by itself, just like the GetPerson method, which is used to find out whether the customer's name exists. – Zack Dec 12 '22 at 06:41

0 Answers0