I have a MEAN application application generated by Yeoman Generator Angular Fullstack . You should only have access to the site by logging in.
Repo for providing logged in here
During logout, if I try to go to '/ products', I am redirected to '/ login' just fine. However, I have a problem redirecting users who are not logged in when the url is "/" or even "localhost: 9000" without a slash.
If I have not logged in and on the login screen and I change '/ login' to just '/' or '', I go to the 'main' in AngularJS and it is treated as registered (I 'm because it recognizes session?) and can click on links to "/ products" or "/ users".
My current .js routes are as follows:
'use strict';
var errors = require('./components/errors');
var auth = require('./controllers/auth');
var passport = require('passport');
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
module.exports = function(app) {
app.route('/:url(api|auth|components|app|bower_components|assets)/*').get(errors[404]);
app.route('/login').get(auth.login).post(auth.loginUser);
app.route('/logout').get(auth.logout);
app.all('*', ensureLoggedIn('/login'));
app.route('/*').get(function(req, res) {
res.sendfile(app.get('appPath') + '/index.html');
});
};
I also tried this with routes:
app.route('/*').get(function(req, res) {
res.sendfile(app.get('appPath') + '/index.html');
});
Which seems to have the same behavior as enabling LoggedIn support in app.all.
Here is a snippet of my routing on the Angular side that uses ui-router:
.config ($stateProvider, $urlRouterProvider, $locationProvider) ->
$httpProvider.interceptors.push('httpInterceptor')
$urlRouterProvider
.otherwise '/'
$stateProvider
.state 'main',
url: '/'
templateUrl: 'app/views/main/main.html'
controller: 'MainCtrl'
.state 'users',
url: '/users'
templateUrl: 'app/views/users/index.html'
controller: 'UsersController'
, '/users'. , auth. Auth , , '/'.
login.jade , . 404.jade, ui-router.
, - . , . .
EDIT:
, , app.route('login'):
app.route('/')
.get(function(req, res) {
res.render('login');
});
uri-router url main '/' '/main.
index.html Angular , . res.redirect routes.js, .