1
0
Fork 0

user session should be initialized by apps

This commit is contained in:
Ruben Meyer 2020-10-01 22:00:50 +02:00
parent 72eef7b480
commit e1299d3857
Signed by: rxbn_
GPG Key ID: BE3BF898BE352FE2
1 changed files with 11 additions and 3 deletions

View File

@ -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) => {