title: Accessing session variables in sailsjs view
body: <p>I am quite new to sailsjs and nodejs. I am trying to create an authentication page, wherein once a user is authenticated, I want to set </p>
  
  <pre><code>req.session.user = user.id
  req.session.authenticated = true
  </code></pre>
  
  <p>I then need to access these values within my main layout.ejs file. I have done so by using </p>
  
  <pre><code>res.locals.user = _.clone( req.session.user )
  </code></pre>
  
  <p>However, I noticed that this clone method has to be called in every function of every controller so as to allow me to be able to access the user from within the views. Is there a better way of accessing session variables in sailsjs globbaly, without having to clone the req.session in every controller. An example of what I am doing can be found here:</p>
  
  <p><a href="http://pastebin.com/HyE2H4Kq">http://pastebin.com/HyE2H4Kq</a></p>
  
  <p>As you can see, I have called the clone method at the beginning of various functions within the controller.</p>