My first post is here. I already explain my problem here and My output expected. Sir Guangyu Bai - MSFT commented my post, you check my post and scroll his answer. I apply his answer to my codes. The link is https://stackoverflow.com/questions/74587990/insert-data-to-firebase-and-set-restriction-to-uiusername-and-password-in-xama/74596335?noredirect=1#comment131744947_74596335.
This is how apply his code. My Username FIeld in UI
`
<Entry
Placeholder="Username"
TextColor="Black"
HorizontalOptions="FillAndExpand"
Margin="0,0,15,0"
PlaceholderColor="Black"
x:Name="entryField_Username"
TextChanged="entryField_Username_TextChanged"/>
` code behind under the textchanged..
`
async private void entryField_Username_TextChanged(object sender, TextChangedEventArgs e)
{
var oldText = e.OldTextValue;
var newText = e.NewTextValue;
// var newText = entryField_Username.Text;
CUSTOMER customer = new CUSTOMER();
// var person = await firebaseHelper.GetPerson(Convert.ToString(EntryText.Text);
var customerName = await customerRepo.GetCustomer(Convert.ToString(entryField_Username.Text));
//if (oldText != string.Empty)
//{
// if(await customerRepo.GetCustomer(Convert.ToString(entryField_Username.Text))
// {
// }
//}
if (customerName != null)
{
entryField_Username.Text = customer.CusFirstName;
// this is a Toast method
// await this.DependencyService.Get<Toast>().Show("Username Already Exist!");
await this.DisplayToastAsync("Username already exist.", 1500);
}
else
{
}
}
`
in my customerRepository file, One if the code or function is..
`
public async Task<List<CUSTOMER>> GetAllCustomer()
{
return (await firebaseClient
.Child("CUSTOMER")
.OnceAsync<CUSTOMER>()).Select(item => new CUSTOMER
{
CusFirstName = item.Object.CusFirstName,
CusID = item.Object.CusID
}).ToList();
}
public async Task<CUSTOMER> GetCustomer(string customerName)
{
// var data = await firebaseClient.Child(nameof(Customer)).PostAsync(JsonConvert.SerializeObject(customer));
//if (!string.IsNullOrEmpty(data.Key))
//{
// return true;
//}
//return false;
var allCustomer = await GetAllCustomer();
await firebaseClient
.Child("CUSTOMER")
.OnceAsync<CUSTOMER>();
return allCustomer.Where(a => a.CusFirstName == customerName).FirstOrDefault();
// var allCustomer = await firebaseClient.Child(nameof("Customer")).OnceAsync<Customer>
}
`
also in that customerRepository file, I set my firebaseclient with the link of my realtime database.
now, I flow is, when I enter the username of the user and hit "check" in the keyboard,just like the image I attached. The image is from google, I just editted it but thats the visual of what Im doing upon create. It will crash and ERROR WILL appear. that is the error :(
Please help me master how to solve the error and achieve my problem. Any link will be commented about my post, will be appreciated, Thank you.
EDIT; base on the user commented to my post, so I check my realtime database, and this is our rules `
{
"rules": {
"some_path": {
"$uid": {
// Allow only authenticated content owners access to their data
".read": "auth !== null && auth.uid === $uid",
".write": "auth !== null && auth.uid === $uid"
}
}
}
}
`
If we set the rules like that,we got this error..
Firebase.Database.FirebaseException: 'Exception occured while processing the request. Url: https://***************************************************************/.json?print=silent Request Data: {/*I comment this out,but this part is like my table property and its data */} Response: { "error" : "Permission denied" } '
This problem caused by the rejected data from the server side.
Since this Exception is thrown because Firebase servers rejected the operation, the way can fix this is by changing the rules in Cloud Firestore Security Rules.