Sign in
Log inSign up
Can anyone please suggest me how to get the username of currently logged in user in React component?

Can anyone please suggest me how to get the username of currently logged in user in React component?

Default profile photo
Anonymous
·Feb 11, 2016

I am trying to make an isomorphic app where I have created React components. Also I integrated the login with node, mongoose and PassportJS. So, now that I am using jade as the templating engine how to get the username sent over the response in the React component?

This is the logged in person function :

app.get('/profile', isLoggedIn, function(req, res) {
        res.render('comment.jade', {
            user : req.user // get the user out of session and pass to template
        });
});

In comment.jade I am doing the following :

doctype html
html
head
    title= title
    link(rel='stylesheet',href='maxcdn.bootstrapcdn.com/bootstrap/3.3.6/cs…)
    script(src="cdnjs.cloudflare.com/ajax/libs/react/0.14.…")
    script(src="cdnjs.cloudflare.com/ajax/libs/react/0.14.…")
    script(src="cdnjs.cloudflare.com/ajax/libs/babel-core/…")
    script(src="maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js…")
body
    block content
        #content
        script(type="text/babel",src='/scripts/example.js')

How to get the username in scripts/example.js?