I followed this example ->
Works fine, but I dont like the way they display the content one time you successfully logged in or logged out.
Its there other way to do X or Y one time user its authenticated ? Example
I have a linear form for login, will be nice to hide that div one time user it's authenticated, but I can't do this
$(document).ready(function(){
if(req.session.user) { $(.class of teh frm to hide).hide(); }
}
I tried too session.user
All the time tells me its undefined. I placed this on layout.
So how I show things on a view if user its authenticated or, if user it's admin ??
Cause atm the only way I see it's authorizate some routes and display specific content via
req.session.success = 'Authenticated as ' + req.session.user.name
+ ' click to <a href="/logout">logout</a>. '
+ ' You may now access <a href="/restricted">/restricted</a>.';
}
Think its not the way to go.
I followed this example -> https://github./visionmedia/express/tree/master/examples/auth
Works fine, but I dont like the way they display the content one time you successfully logged in or logged out.
Its there other way to do X or Y one time user its authenticated ? Example
I have a linear form for login, will be nice to hide that div one time user it's authenticated, but I can't do this
$(document).ready(function(){
if(req.session.user) { $(.class of teh frm to hide).hide(); }
}
I tried too session.user
All the time tells me its undefined. I placed this on layout.
So how I show things on a view if user its authenticated or, if user it's admin ??
Cause atm the only way I see it's authorizate some routes and display specific content via
req.session.success = 'Authenticated as ' + req.session.user.name
+ ' click to <a href="/logout">logout</a>. '
+ ' You may now access <a href="/restricted">/restricted</a>.';
}
Think its not the way to go.
Share Improve this question asked Sep 17, 2012 at 10:41 NonyckNonyck 6821 gold badge13 silver badges29 bronze badges1 Answer
Reset to default 7It is better to use your template engine to show different contents instead of client-side javascript. If you are using jade, do the following:
In your app.js create a variable that is passed to every view if the user is logged in:
app.use(function(req, res, next){
// all the stuff from the example
if (req.session.user) {
res.locals.user = req.session.user
}
next();
});
Use this variable in your template engine (for example jade):
if user
// show stuff here
else
// for everyone else
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745345248a4623513.html
评论列表(0条)