简体   繁体   中英

How to know which user has generated a Firebase event?

I am using Firebase real-time database in my project and for now, I am not using any authentication method meaning that all sign-in methods on Firebase are disabled and there is no rule defined on the Firebase database too:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

I am trying to implement a collaborative text editing app so several users at the same time might be updating the same text. So in my app I am observing the corresponding text editing events sent by Firebase and therefore can keep the text synced for all users working on the same content.

My question is, when a Text Editing event is received by the app how come I can know who (which user) has made that change on Firebase (Whether the event I just received is as a result of a change in the text by User1 or User2 or so on). Because currently, I know that somebody has made a change in the text (because I receive an event) but I don't know who had made it. Any help? Thanks

Any general guidance would help.

If you want to identify users without requiring them to sign in, you're looking for Firebase's anonymous authentication . In Objective-C this is as simple as:

[[FIRAuth auth]
 signInAnonymouslyWithCompletion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
   // ...
 }];

And then you can identify the user with:

[[[FIRAuth auth].currentUser].uid];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM