Closed msteffan closed 9 years ago
That code looks correct. The only conclusion I can draw is that the value of user
is not what you expect at that point.
tip: Please post code as code, using triple back-tics (```). It makes it much easier to test.
unfortuanely, handlebars is extremely limited.
can you move the [0]["spotifyId"]
to the res.locals
function?
Or do something like res.render("/someRoute", {user: user[0]["spotifyId"]})
, so you can access {{user}}
.
We tested that previously, @jshawl. We used:
app.use(function(req, res, callback){
console.log("req user is", req.user[0]["spotifyId"]);
if (req.user){
res.locals.user = req.user
//console.log(req.user);
}
callback();
})
(and that's just to console.log the value of user[0]["spotifyId"]) it returns the same error:
I think that's from your console.log
line. Try moving that inside your if
statement. It's going to error if you try to call req.user[0]
anywhere req.user
isn't defined. If you move that inside the if
, it ensures that you'll only call req.user[0]
if req.user
exists.
Yes!! I created a new variable for spotifyId and now that works in hbs. THANK YOU, all!
Following up on the spotify/users issue from earlier... We have a user object as follows:
but it returns this error when we try to embed it in hbs:
Everything we can find indicates that this is the right way to access the first item in the object, but when we call it as
use[0]["spotifyId"]
that also returns an error. We even tested it in repl.it and that works, but this call doesn't. Any ideas?