Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. //two functions that get UIDs
  2. //store them in an array
  3. //iterate throught that array
  4. //to find a matching email
  5.  
  6. //sample Data:
  7. // firebase project
  8. // -users
  9. // -DSDFLDSFDF
  10. // -email: "hello@gmail.com"
  11. // -SDSDFDFSDF
  12. // -email: "jimbob@gmail.com"
  13.  
  14. //how to run functions in console
  15. //getStuff("/users")
  16. //getEmail("hello@gmail.com")
  17. //emailSavedPath
  18.  
  19.  
  20.  
  21. var arrayMe = [];
  22. function getStuff(path) {
  23. //run for Each loop and get all incremental children off of the /users branch
  24. var database = firebase.database().ref(path);
  25. database.on('value', function(snapshot){
  26. for(var item in snapshot.val()){
  27. //push each UID into an array
  28. arrayMe.push(item);
  29. }
  30. //log the array of UIDs
  31. console.log(arrayMe);
  32. });
  33.  
  34. }
  35.  
  36. var emailSavedPath = "";
  37. var matchFound = "";
  38. function getEmail(comparingEmail){
  39. //iterate through all arrayMe elements
  40. for(var item in arrayMe){
  41. var database = firebase.database().ref("/users/"+arrayMe[item]+"/email");
  42. database.on('value', (snapshot) =>{
  43. console.log(snapshot.val());
  44.  
  45. //compare an arrayMe element with passed in arguement
  46. if(snapshot.val()==comparingEmail){
  47. //if found, store path to email in 'savedEmailPath'
  48. console.log("Found match!");
  49. emailSavedPath = "/users/"+arrayMe[item];
  50. }else{
  51. console.log("Match not found!");
  52. matchFound="false";
  53. }
  54.  
  55. });
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement