My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
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='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css')
    script(src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js")
    script(src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js")
    script(src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/6.1.19/browser.js")
    script(src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js")
body
    block content
        #content
        script(type="text/babel",src='/scripts/example.js')

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