Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:36:37+00:00 2026-06-12T17:36:37+00:00

I am using passport to login my users. When a user logs into my

  • 0

I am using passport to login my users. When a user logs into my app, the username will be displayed in the header.

This is my header.jade:

div#header_content
input(type='text',name='search',id='globle_search')
span#user_status
    if(req.isAuthenticated())
        a(class='user_menu_btn',href='home', target='_blank' )  req.user.username
        a(class='user_menu_btn',href='logout') Logout
    else
        a(id='login_btn',href='login',class='user_status_btn') login

If I run the app, I get an error that says:

 ReferenceError: F:\shopping\views\includes\header.jade:4
 req is not defined

This is my index route:

app.get('/',index.index);

exports.index = function(req, res){
  res.render('index', { title: 'Express' });
};

How do I maintain the login status in the header?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:36:39+00:00Added an answer on June 12, 2026 at 5:36 pm

    To access req within the view, it has to be member of the locals object passed to the view engine — which it won’t be by default.

    // before: app.use(app.router);
    app.use(function (req, res, next) {
        res.locals.req = req;
        next();
    });
    

    Though, since user and isAuthenticated are the what you need from req, you can just attach them directly:

    // before: app.use(app.router);
    app.use(function (req, res, next) {
        res.locals({
            get user() { // as a getter to delay retrieval until `res.render()`
                return req.user;
            },
    
            isAuthenticated: function () {
                return req.user != null;
            }
        })
    
        next();
    });
    
    if isAuthenticated()
        // ...
        a(...) #{user.username}
    else
        // ...
    

    See res.locals and app.locals for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to integrate passport into my nodejs server using connect, but can't seem
I'm developing a node.js app where I'm using passport to build OAuth authentication system.
I'm trying to save a user that authenticated through GitHub into mongodb. I'm using
I'm using a passport-local strategy for authenticate users. I followed the guide given by
I am using Passport-Local (https://github.com/jaredhanson/passport-local) to authenticate with node.js. So far this example works
i'm using the passport module (github authentication) in my app and i want to
I tried writing a skeleton app that authenticates using Mozilla Persona using this tutorial
I'm using passport.js and I'm wounding if I can link a facebook id to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.