Send data specific to user group Node Express
<p>I want to send a navigation object that can be rendered in an Express application that is specific to the user group. I though one way to do it was to add this middleware to each route:</p>

<pre><code>var nav = function() {
    return function(req,res,next) {
        res.nav = [];
        var assignednav = [{
                link: '../console/my-ads',
                text: 'My Ads'
            },
            {
                link: '../console/snippet',
                text: 'Snippet'
            },
            {
                link: '../console/answer',
                text: 'Answer Calls'
            }];
        if (req.user &amp;&amp; req.user.companyid != null){
            res.nav = assignednav;
        } else {
            res.nav = [];
        }
        next();
    }

};
</code></pre>

<p>And then attach it to the routes I am interested in receiving the object.</p>

<pre><code>router.get('/analytics', assignedUser(), function(req, res) {
    res.render('console/analytics', nav());
});
</code></pre>

<p>Currently I get an error: <code>Cannot set property 'nav' of undefined</code>. What am I doing wrong. Is this a good approach?</p>