Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //two functions that get UIDs
- //store them in an array
- //iterate throught that array
- //to find a matching email
- //sample Data:
- // firebase project
- // -users
- // -DSDFLDSFDF
- // -email: "hello@gmail.com"
- // -SDSDFDFSDF
- // -email: "jimbob@gmail.com"
- //how to run functions in console
- //getStuff("/users")
- //getEmail("hello@gmail.com")
- //emailSavedPath
- var arrayMe = [];
- function getStuff(path) {
- //run for Each loop and get all incremental children off of the /users branch
- var database = firebase.database().ref(path);
- database.on('value', function(snapshot){
- for(var item in snapshot.val()){
- //push each UID into an array
- arrayMe.push(item);
- }
- //log the array of UIDs
- console.log(arrayMe);
- });
- }
- var emailSavedPath = "";
- var matchFound = "";
- function getEmail(comparingEmail){
- //iterate through all arrayMe elements
- for(var item in arrayMe){
- var database = firebase.database().ref("/users/"+arrayMe[item]+"/email");
- database.on('value', (snapshot) =>{
- console.log(snapshot.val());
- //compare an arrayMe element with passed in arguement
- if(snapshot.val()==comparingEmail){
- //if found, store path to email in 'savedEmailPath'
- console.log("Found match!");
- emailSavedPath = "/users/"+arrayMe[item];
- }else{
- console.log("Match not found!");
- matchFound="false";
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement