I\'m developing a web app on the MEAN stack (MongoDB, Express, AngularJS, and node.js). I\'m developing a login system, and will also have some of the Angular routes protected s
I ended up combining my original workflow with Express's auth example, seen here. It is as follows:
$rootScope and considered logged in.$rootScope.user is unset (if it needs to be), and the user is redirected to the login page.user object (used to store in the $rootScope as previously mentioned).restrict function which ensures that a session exists before sending any data to the client. It returns a 401 if no session exists, which is then handled on the Angular side using this HTTP interceptor to unset $rootScope.user and redirect to the login screen.$rootScope.user is set to null, and the user is redirected back to the front page.