user session should be initialized by apps
This commit is contained in:
parent
72eef7b480
commit
e1299d3857
@ -1,19 +1,27 @@
|
||||
var express = require('express');
|
||||
var route = express.Router();
|
||||
|
||||
const cfg = require(global['__dirname']+'/bin/config');
|
||||
|
||||
route.use((req, res, next) => {
|
||||
if(!req.session || !req.session.user) {
|
||||
if(!req.path.startsWith('/api')) {
|
||||
let path = (global['gds'].cfg.web.rootUrl+'/auth');
|
||||
let path = (cfg.web.rootUrl+'/auth');
|
||||
|
||||
if(global['gds'].cfg.web.doubleSlashCheck) path = path.replace(/\/+/g, "/");
|
||||
if(cfg.web.doubleSlashCheck) path = path.replace(/\/+/g, "/");
|
||||
|
||||
res.redirect(path);
|
||||
} else {
|
||||
res.redirect('/auth'+req.path);
|
||||
}
|
||||
} else next();
|
||||
} else {
|
||||
// initialize User
|
||||
if(req.session.user.initializeUser) {
|
||||
// do it
|
||||
req.session.user.initializeUser = false;
|
||||
}
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
route.get('/', (req, res) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user