Xamarin访问使用Nuget软件包firebaseauthentication.net的firebase实时数据库

发布于 2025-02-10 09:37:00 字数 1597 浏览 0 评论 0原文

IM在Firebase中的初学者和IM使用两个Nuget软件包FirebaseAthentication.net和firebaseadatabase.net。 IM试图写入一个受保护的Firebase实时数据库,该数据库具有看起来像这样的规则,

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
        
      }
    }
  }
}

我随机尝试了signwithoAuthasync方法,但是它会引发异常[邮件auth类型类型connot被这样使用。使用方法指定来发送电子邮件&密码身份验证]

private async void Button_Clicked(object sender, EventArgs e)
        {

            try
            {
                var authProvider = new FirebaseAuthProvider(new FirebaseConfig(webApiKey));
                var savedfirebaseauth = JsonConvert.DeserializeObject<FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
                await authProvider.SignInWithOAuthAsync(FirebaseAuthType.EmailAndPassword, savedfirebaseauth.FirebaseToken);
                

                //inserting info into the database
               
                await firebaseClient.Child("users").Child("some uid1").PutAsync(new userinfo
                {

                    firstName = "dtox",
                    secondName = "solo"
                });

                //clear the entry
                recordData.Text = "";

            }catch(Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
            }
        }

请求让我知道我的问题是否需要更澄清,谢谢。 Frank Van先生

im beginner in firebase and im using two nuget packages FirebaseAuthentication.net and FirebaseDatabase.net . im trying to write to a protected firebase realtime database that has a rule that look like this

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth != null && auth.uid == $uid",
        ".write": "auth != null && auth.uid == $uid"
        
      }
    }
  }
}

i randomly tryed SignInWithOAuthAsync method however it throws an Exception [ mail auth type connot be used like this. use method specifc to email & password authentication]

private async void Button_Clicked(object sender, EventArgs e)
        {

            try
            {
                var authProvider = new FirebaseAuthProvider(new FirebaseConfig(webApiKey));
                var savedfirebaseauth = JsonConvert.DeserializeObject<FirebaseAuth>(Preferences.Get("MyFirebaseRefreshToken", ""));
                await authProvider.SignInWithOAuthAsync(FirebaseAuthType.EmailAndPassword, savedfirebaseauth.FirebaseToken);
                

                //inserting info into the database
               
                await firebaseClient.Child("users").Child("some uid1").PutAsync(new userinfo
                {

                    firstName = "dtox",
                    secondName = "solo"
                });

                //clear the entry
                recordData.Text = "";

            }catch(Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
            }
        }

pleace let me know if my question needs more Clarificatio thanks in advance.
mr Frank van

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2025-02-17 09:37:00

不用担心我得到了你

//first you need to authenticate before writtng to your database
var auth = await authProvider.SignInWithEmailAndPasswordAsync(your email, your password);
                var firebaseClientt = new FirebaseClient(
                  "your url ",
                  new FirebaseOptions
                  {
                      AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken)
                  });
//now you can write to your database
 await firebaseClientt.Child("users").Child("some uid").PutAsync(new userinfo
                {

                    firstName = "dtox",
                    secondName = "solo"
                });

dont worry i got you

//first you need to authenticate before writtng to your database
var auth = await authProvider.SignInWithEmailAndPasswordAsync(your email, your password);
                var firebaseClientt = new FirebaseClient(
                  "your url ",
                  new FirebaseOptions
                  {
                      AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken)
                  });
//now you can write to your database
 await firebaseClientt.Child("users").Child("some uid").PutAsync(new userinfo
                {

                    firstName = "dtox",
                    secondName = "solo"
                });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文