0

Is is possible to get the user UID of the user who wrote/updated/deleted data from the database?

Ben Flowers
  • 1,434
  • 7
  • 21
  • 49
  • Are you trying to determine this within Cloud Functions? Or somewhere else? It'll probably be easier to help if you give some more context, or better yet, the [minimal code that reproduces where you're stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen Sep 26 '17 at 08:59
  • If you're trying to determine if from Cloud Functions, see the answer here: https://stackoverflow.com/questions/42750060/getting-the-user-id-from-a-database-trigger-in-cloud-functions-for-firebase – Frank van Puffelen Sep 26 '17 at 09:00

1 Answers1

0

When you are using Firebase authentication you can get the uid of the authenticated user using the following lines of code:

FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
    String uid = firebaseUser.getUid();
}

On the other hand, you need to know that Firebase does not store meta-data or other informations regarding write operation. To achieve this, you need to create your own mechanism.

In your case, when a user creates a record, store his uid on a location from where you can query for that particular uid and use it for what you want.

In case you are trying to determine this within Cloud Functions i recomand you take a look at Firebase Cloud Functions and at jacobawenger's answer from this post

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193