I am so tired to form up explanatory, coherent sentences, but at the same time I really like to share a user authentication service that I wrote for AngularJS. Hence, pardon my brevity.
In this example I use RailwayJS with CoffeeScript both at the client- and server-side. (See my previous post on auto-compiling assets with connect-assets.) Here is the scenario: You have
assignments.html such that only authenticated users are allowed.
First things first, here is our
Then we implement our controller
/app/controllers/home_controller.coffee as follows.
Note that the
authenticate used in
login action handler is meant to be provided by you.
Later, we write
/app/views/home/index.ejs to fire up AngularJS:
We first start by implementing
app.js of AngularJS in
The extra bit for listening on
$routeChangeStart is to check access to authentication required pages.
app.js, we implement
For each controller, we implement a view, that is,
And here goes the magic,
Hope it works for you as well.