step-up-labs / firebase-authentication-dotnet

C# library for Firebase Authentication
MIT License
377 stars 130 forks source link

Firebase RealTime Database Ruleset Premission Denied. #154

Closed Nightfly-student closed 2 years ago

Nightfly-student commented 3 years ago

Hello, I am using this package to sign in/up with firebase, but I am also using realtime database but the database does not allow me to use rulesets such as

{ "rules": { ".read": true, ".write": "auth.uid != null" } }

I am using this to connect:

`async void LoginLog(object sender, EventArgs e) { var authProvider = new FirebaseAuthProvider(new Firebase.Auth.FirebaseConfig(WebApi)); try { var auth = await authProvider.SignInWithEmailAndPasswordAsync(UsernameEntry.Text, PasswordEntry.Text); var content = await auth.GetFreshAuthAsync(); var serializedcontent = JsonConvert.SerializeObject(content); Preferences.Set("userSession", content.User.Email); Preferences.Set("MyFirebaseRefreshToken", serializedcontent);

            if (string.IsNullOrEmpty(Preferences.Get("username", "")))
            {
                retrieveData();
                if (string.IsNullOrEmpty(Preferences.Get("username", "")))
                {
                    await Navigation.PushModalAsync(new ChooseYourUsername());
                } else
                {
                    await Navigation.PushModalAsync(new Main());
                }
            } else
            {
                await Navigation.PushModalAsync(new Main());
            }
        }
        catch (FirebaseAuthException ex)
        {              
            await App.Current.MainPage.DisplayAlert("Alert", ex.Reason.ToString(), "Ok");
        }
    }`

and this to check if you are logged in:

async private void GetProfileInformationAndRefreshToken() { var authProvider = new FirebaseAuthProvider(new FirebaseConfig(WebApi)); try { var savedFirebaseAuth = JsonConvert.DeserializeObject<Firebase.Auth.FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", "")); var RefreshedContent = await authProvider.RefreshAuthAsync(savedFirebaseAuth); Preferences.Set("MyFirebaseRefreshToken", JsonConvert.SerializeObject(RefreshedContent)); } catch (Exception ex) { Console.WriteLine(ex.Message); await App.Current.MainPage.DisplayAlert("Alert", "Oh no! Token expired", "Ok"); await Navigation.PushModalAsync(new LoginPage()); } }

Does anyone see a solution?

Is it mine fault or the fault of this auth.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

Closing the issue due to inactivity. Feel free to re-open