I am learning MEAN stack with MEANJS framework.
I would like to see some examples of how to configure the routes on the client side:
1) How to disallow unlogged users to access specific route?
2) How to redirect users to login page, and once authenticated return them to the specific route?
3) Do I have to install any extra module, or it could be done with default meanjs dist?
This is an example of a meanjs module route:
'use strict';
//Setting up route
angular.module('cart').config(['$stateProvider',
function($stateProvider) {
// Cart state routing
$stateProvider.
state('cart', {
url: '/cart',
templateUrl: 'modules/cart/views/cart.client.view.html'
});
}
]);
I have seen that when a user is authenticated I have an authentication object available in the $scope as follows:
{
"user": {
"_id": "54cf7e730d7da864c0d511f5",
"displayName": "Korner Foxiertw",
"provider": "local",
"username": "fox23",
"__v": 0,
"updated": "2015-02-04T19:55:38.435Z",
"created": "2015-02-02T13:41:07.791Z",
"roles": [
"user"
],
"email": "[email protected]",
"lastName": "Korner",
"firstName": "Foxiertw"
}
}
How to deal with this info?
I have seen examples of the above, but not specifically for meanjs framework. For example, this one:
http://www.seanmarchetti.com/authentication_with_angularui_router.html
These are the libs I have in my client-side app:
"dependencies": {
"bootstrap": "~3",
"angular": "~1.3",
"angular-resource": "~1.2",
"angular-mocks": "~1.2",
"angular-cookies": "~1.2",
"angular-animate": "~1.3",
"angular-touch": "~1.2",
"angular-sanitize": "~1.2",
"angular-bootstrap": "~0.11.2",
"angular-ui-utils": "~0.1.1",
"angular-ui-router": "~0.2.11",
"font-awesome": "latest"
}
Kind Regards.