0

I'm tring to get the authentificated users from firebase

enter image description here

I can get all the users from Database but the key is an id and i need email

enter image description here

this is the code i use in ReactJS to get the users from database

import firebase from "firebase"; import React from "react"; import "./App.css";

    const config = { apiKey:  ..., authDomain: ... ,databaseURL: ..., projectId: ..., storageBucket: , messagingSenderId: ..., appId: ...};

    firebase.initializeApp(config);

    function App() {
      const itemsRef = firebase.database().ref("users");
      itemsRef.on("value", (snapshot) => {
        let items = snapshot.val();
        console.log(items); // log the users but with id, need email      
      });


      return (
        ...
      );
    }

items is an array with data like this

"3yDtn8xZJVUFOlsQgSJsku6SfXx2" : {
  "trips" : {
    "-Lyut2ozCnkDJo-OLUcI" : {
      "arrival_country" : "Afghanistan",
      "arrival_date" : "2020-01-19T01:01:42.743+02:00",
      "created_at" : 1579388517837,
      "departure_country" : "France",
      "departure_date" : "2020-01-19T01:01:42.744+02:00",
      "name" : "123",
      "residence_country" : "Algeria",
      "status" : 0,
      "trip_name" : "123"
    }
  }
},

how to get the emails ( or more info) of users ?

AlainIb
  • 4,544
  • 4
  • 38
  • 64
  • Did you store the user's email in the database? I can't tell from what you've shown here. – Doug Stevenson Apr 04 '20 at 22:52
  • i just get this project today and i don't know what it was done. there is email in the first screen shot in "authentificated" panel but i can read only the "database" just under it with `firebase.database()` – AlainIb Apr 04 '20 at 22:58
  • 1
    The database query you're making doesn't have anything to do with the top screenshot showing data in Firebase Authentication. It's only looking at data in the bottom showing what's in Realtime Database. They're completely different things. – Doug Stevenson Apr 04 '20 at 23:01
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export JSON link in the overflow menu (⠇) of [your Firebase Database console](https://console.firebase.google.com/project/_/database/data/). Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Apr 04 '20 at 23:02
  • @DougStevenson yes i know, i want to query the Authentication or get the user's email because i just get id now and it's not understable for human – AlainIb Apr 05 '20 at 08:12
  • @FrankvanPuffelen i putted the json, but i does'nt contain the email or user's info used for auth because old dev doesn't store them there (or at all) – AlainIb Apr 05 '20 at 08:16
  • 1
    There is no way to the client-side SDK to get the email for a UID, as that would be a security risk. The common way to implement the use-case is to store a mapping from all user's UIDs to their email address in the database, or by creating a custom API with the Admin SDK. See https://stackoverflow.com/a/38040790, https://stackoverflow.com/a/40870152, https://stackoverflow.com/q/29889729, and more from https://stackoverflow.com/search?q=%5Bfirebase-authentication%5D+get+email+by+uid – Frank van Puffelen Apr 05 '20 at 14:27

0 Answers0