I am trying to use a session variable in my view file. My controller code is like this
User.find()
.where({ username: username })
.where({ password: password })
.exec(function(err, users) {
if(users.length == 1){
req.session.user_detail = users;
res.redirect('/member');
}else{
console.log(err);
}
});
I want to use the req.session.user_detail in my member.ejs file.
For the record, in case someone stumbles onto this question instead of this one, req.session
is indeed available by default in your Sails views. So you can just do
<%= JSON.stringify(req.session.user_detail) %>
in your view; there's no need to pass it explicitly in res.locals
. You can also loop through the users with:
<% req.session.user_detail.forEach(function(user_detail) { %>
<%= JSON.stringify(user_detail) %>
<% }) %>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments