Change view based on user role with MEAN + Passport
You can check whether the user is authentication on the server side using
req.isAuthenticated()
Call this value in your server side code and pass the result to your view or to the client side code in some other manner, a separate ajax call to the server if necessary. This comes from PassportJS
Found in this answer:Documentation for "ensureAuthentication" "isAuthenticated" passport's functions?
Your seriliazeUser
and deserializeUser
functions look ok.
As far as I remember there is some code in mean stack that sets window.user
after user is authenticated, and there is also a Global
service on angular side that uses this information to set authenticated
value. You can use that information to alter your view.
Take a look at Header controller code.
https://github.com/linnovate/mean/blob/master/public/js/controllers/header.js