1

I get an object from my code

       const username = await firebase
        .database()
        .ref("users/" + authUser + "/name")
        .once("value")
        .then(function(snapshot) {
          return snapshot;
        });

Its value is "testname". Its logging everything correct to console. But if I try to reuse my username for example in

      const url = `https://url.com/users/${username}/${authUser}/posts.json?auth=${token}`;

I get in my console.log

https://url.com/users/[object Object]/...

I am pretty new to firebase and JS but I think I have to transform my object to a string? How to achive this?

5
  • JSON.stringify(object)? Commented Mar 9, 2020 at 11:37
  • Got it now via var myJSON = JSON.stringify(username); But it return "testname". Do you know how to get rid of the ""? Commented Mar 9, 2020 at 11:38
  • What is the use case of removing this ""? Commented Mar 9, 2020 at 11:41
  • I am writing via REST Api to my firebase with the username. The structure is now /users/"testname"/posts but should be "users/testname/posts Commented Mar 9, 2020 at 11:42
  • yourString.substring(1, yourString.length-1) or go with yourString.slice(1, -1); Commented Mar 9, 2020 at 11:43

1 Answer 1

1

Use the following to convert your object to a string

JSON.stringify(object)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.