How to insert the currentUser email into the Realtime Database












0















Everytime i tried inserting the users email into the database, there will be an error saying "First Arguement is an invalid path".How do i get pass this



return (

<View style={styles.MainContainer}>
<Text style={styles.textStyle}>Rate this Song</Text>
<Text style={styles.textStyleSmall}> {list.title}</Text>
<Text style={styles.textStyleSmall}> {list.artist}</Text>
{/*View to hold our Stars*/}
<View style={styles.childView}>{React_Native_Rating_Bar}</View>

<Text style={styles.textStyle}>
{/*To show the rating selected*/}
{this.state.Default_Rating} / {this.state.Max_Rating}
</Text>

<TouchableOpacity
activeOpacity={0.7}
style={styles.button}

onPress={() => {
firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})
alert('Thank you')}
}>
<Text>Continue</Text>
</TouchableOpacity>
<Text>
{currentUser && currentUser.email}
</Text>
</View>
);


}



The expected result is when i view the database in firebase, the users account name should be there alongside with the title an artist name










share|improve this question























  • What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

    – Doug Stevenson
    Jan 2 at 7:16













  • the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

    – khai khai
    Jan 2 at 7:27
















0















Everytime i tried inserting the users email into the database, there will be an error saying "First Arguement is an invalid path".How do i get pass this



return (

<View style={styles.MainContainer}>
<Text style={styles.textStyle}>Rate this Song</Text>
<Text style={styles.textStyleSmall}> {list.title}</Text>
<Text style={styles.textStyleSmall}> {list.artist}</Text>
{/*View to hold our Stars*/}
<View style={styles.childView}>{React_Native_Rating_Bar}</View>

<Text style={styles.textStyle}>
{/*To show the rating selected*/}
{this.state.Default_Rating} / {this.state.Max_Rating}
</Text>

<TouchableOpacity
activeOpacity={0.7}
style={styles.button}

onPress={() => {
firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})
alert('Thank you')}
}>
<Text>Continue</Text>
</TouchableOpacity>
<Text>
{currentUser && currentUser.email}
</Text>
</View>
);


}



The expected result is when i view the database in firebase, the users account name should be there alongside with the title an artist name










share|improve this question























  • What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

    – Doug Stevenson
    Jan 2 at 7:16













  • the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

    – khai khai
    Jan 2 at 7:27














0












0








0








Everytime i tried inserting the users email into the database, there will be an error saying "First Arguement is an invalid path".How do i get pass this



return (

<View style={styles.MainContainer}>
<Text style={styles.textStyle}>Rate this Song</Text>
<Text style={styles.textStyleSmall}> {list.title}</Text>
<Text style={styles.textStyleSmall}> {list.artist}</Text>
{/*View to hold our Stars*/}
<View style={styles.childView}>{React_Native_Rating_Bar}</View>

<Text style={styles.textStyle}>
{/*To show the rating selected*/}
{this.state.Default_Rating} / {this.state.Max_Rating}
</Text>

<TouchableOpacity
activeOpacity={0.7}
style={styles.button}

onPress={() => {
firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})
alert('Thank you')}
}>
<Text>Continue</Text>
</TouchableOpacity>
<Text>
{currentUser && currentUser.email}
</Text>
</View>
);


}



The expected result is when i view the database in firebase, the users account name should be there alongside with the title an artist name










share|improve this question














Everytime i tried inserting the users email into the database, there will be an error saying "First Arguement is an invalid path".How do i get pass this



return (

<View style={styles.MainContainer}>
<Text style={styles.textStyle}>Rate this Song</Text>
<Text style={styles.textStyleSmall}> {list.title}</Text>
<Text style={styles.textStyleSmall}> {list.artist}</Text>
{/*View to hold our Stars*/}
<View style={styles.childView}>{React_Native_Rating_Bar}</View>

<Text style={styles.textStyle}>
{/*To show the rating selected*/}
{this.state.Default_Rating} / {this.state.Max_Rating}
</Text>

<TouchableOpacity
activeOpacity={0.7}
style={styles.button}

onPress={() => {
firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})
alert('Thank you')}
}>
<Text>Continue</Text>
</TouchableOpacity>
<Text>
{currentUser && currentUser.email}
</Text>
</View>
);


}



The expected result is when i view the database in firebase, the users account name should be there alongside with the title an artist name







firebase react-native






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 7:13









khai khaikhai khai

154




154













  • What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

    – Doug Stevenson
    Jan 2 at 7:16













  • the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

    – khai khai
    Jan 2 at 7:27



















  • What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

    – Doug Stevenson
    Jan 2 at 7:16













  • the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

    – khai khai
    Jan 2 at 7:27

















What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

– Doug Stevenson
Jan 2 at 7:16







What exactly is this line of code supposed to do? firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})? That's a very unconventional looking database reference. What does it mean for the account name to "be there"?

– Doug Stevenson
Jan 2 at 7:16















the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

– khai khai
Jan 2 at 7:27





the database ref is to insert the title of the song, the artist and also the currentuser email. I can insert the title and the artist of the song just fine. I just have issues with inserting the currentUser into the database

– khai khai
Jan 2 at 7:27












1 Answer
1






active

oldest

votes


















0














The way you are creating your song ratings key is error prone because you are not checking if it conforms to the limitations of a Firebase database key:





  1. Maximum 768 Bytes

  2. Keys are UTF-8 encoded and can't contain new lines or any of the following characters:
    . $ # [ ] / or any ASCII control characters (0x00 - 0x1F and 0x7F)




You are already certainly breaking the second constraint since email addresses are containing at least one . character.



firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})


Consider sanitizing the data before using it as a key or finding a structure where you don't use arbitrary data such as "song titles" and "artist names" to become keys without first being sanitized.



Sidenote: you probably don't want to store all data as "root nodes" in your database. Consider structuring them under a "ratings" node first.



If all you need is a unique key to directly address a user's rating for the current song by a certain artist, then you can create a hash over that string to create a valid Firebase key.



firebase.database().ref("ratings").child(MD5(list.title + list.artist + currentUser.email)).set({Ratings : (this.state.Default_Rating)})





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002573%2fhow-to-insert-the-currentuser-email-into-the-realtime-database%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The way you are creating your song ratings key is error prone because you are not checking if it conforms to the limitations of a Firebase database key:





    1. Maximum 768 Bytes

    2. Keys are UTF-8 encoded and can't contain new lines or any of the following characters:
      . $ # [ ] / or any ASCII control characters (0x00 - 0x1F and 0x7F)




    You are already certainly breaking the second constraint since email addresses are containing at least one . character.



    firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})


    Consider sanitizing the data before using it as a key or finding a structure where you don't use arbitrary data such as "song titles" and "artist names" to become keys without first being sanitized.



    Sidenote: you probably don't want to store all data as "root nodes" in your database. Consider structuring them under a "ratings" node first.



    If all you need is a unique key to directly address a user's rating for the current song by a certain artist, then you can create a hash over that string to create a valid Firebase key.



    firebase.database().ref("ratings").child(MD5(list.title + list.artist + currentUser.email)).set({Ratings : (this.state.Default_Rating)})





    share|improve this answer






























      0














      The way you are creating your song ratings key is error prone because you are not checking if it conforms to the limitations of a Firebase database key:





      1. Maximum 768 Bytes

      2. Keys are UTF-8 encoded and can't contain new lines or any of the following characters:
        . $ # [ ] / or any ASCII control characters (0x00 - 0x1F and 0x7F)




      You are already certainly breaking the second constraint since email addresses are containing at least one . character.



      firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})


      Consider sanitizing the data before using it as a key or finding a structure where you don't use arbitrary data such as "song titles" and "artist names" to become keys without first being sanitized.



      Sidenote: you probably don't want to store all data as "root nodes" in your database. Consider structuring them under a "ratings" node first.



      If all you need is a unique key to directly address a user's rating for the current song by a certain artist, then you can create a hash over that string to create a valid Firebase key.



      firebase.database().ref("ratings").child(MD5(list.title + list.artist + currentUser.email)).set({Ratings : (this.state.Default_Rating)})





      share|improve this answer




























        0












        0








        0







        The way you are creating your song ratings key is error prone because you are not checking if it conforms to the limitations of a Firebase database key:





        1. Maximum 768 Bytes

        2. Keys are UTF-8 encoded and can't contain new lines or any of the following characters:
          . $ # [ ] / or any ASCII control characters (0x00 - 0x1F and 0x7F)




        You are already certainly breaking the second constraint since email addresses are containing at least one . character.



        firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})


        Consider sanitizing the data before using it as a key or finding a structure where you don't use arbitrary data such as "song titles" and "artist names" to become keys without first being sanitized.



        Sidenote: you probably don't want to store all data as "root nodes" in your database. Consider structuring them under a "ratings" node first.



        If all you need is a unique key to directly address a user's rating for the current song by a certain artist, then you can create a hash over that string to create a valid Firebase key.



        firebase.database().ref("ratings").child(MD5(list.title + list.artist + currentUser.email)).set({Ratings : (this.state.Default_Rating)})





        share|improve this answer















        The way you are creating your song ratings key is error prone because you are not checking if it conforms to the limitations of a Firebase database key:





        1. Maximum 768 Bytes

        2. Keys are UTF-8 encoded and can't contain new lines or any of the following characters:
          . $ # [ ] / or any ASCII control characters (0x00 - 0x1F and 0x7F)




        You are already certainly breaking the second constraint since email addresses are containing at least one . character.



        firebase.database().ref("Song title: "+ list.title +''+ "Artist: "+ list.artist + currentUser.email).set({Ratings : (this.state.Default_Rating)})


        Consider sanitizing the data before using it as a key or finding a structure where you don't use arbitrary data such as "song titles" and "artist names" to become keys without first being sanitized.



        Sidenote: you probably don't want to store all data as "root nodes" in your database. Consider structuring them under a "ratings" node first.



        If all you need is a unique key to directly address a user's rating for the current song by a certain artist, then you can create a hash over that string to create a valid Firebase key.



        firebase.database().ref("ratings").child(MD5(list.title + list.artist + currentUser.email)).set({Ratings : (this.state.Default_Rating)})






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 9:22

























        answered Jan 2 at 9:12









        Dennis AlundDennis Alund

        8001418




        8001418
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002573%2fhow-to-insert-the-currentuser-email-into-the-realtime-database%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]