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 so that only logged-in users can access them. I'm trying to think of the best way to approach the architecture of this.
I'm thinking of the current workflow:
Does this approach make sense? Is it secure, and will it be relatively efficient/quick in execution?
The MEAN stack is a JavaScript-based framework for developing web applications. MEAN is named after MongoDB, Express, Angular, and Node, the four key technologies that make up the layers of the stack. MongoDB — document database. Express(.js) — Node.js web framework. Angular(.js) — a client-side JavaScript framework.
MEAN stack is an acronym for a technology stack that uses popular web application development tools and technologies namely MongoDB, Express. js, Angularjs (or Angular), and Node. js. MongoDB is a popular database server that stores data structures in a binary JSON format.
The MEAN stack is a software stack—that is, a set of the technology layers that make up a modern application—that's built entirely in JavaScript. MEAN represents the arrival of JavaScript as a “full-stack development” language, running everything in an application from front end to back end.
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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With