UI Admin aproape finalizat
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const checkSession = (req, res, next) => {
|
||||
const configPath = path.join(__dirname, '..', 'config', 'credentials.json');
|
||||
const configFile = fs.readFileSync(configPath);
|
||||
const config = JSON.parse(configFile);
|
||||
|
||||
const userEmail = req.cookies.email;
|
||||
|
||||
if (req.path === '/login') {
|
||||
next();
|
||||
} else {
|
||||
if (userEmail && decodeURIComponent(userEmail) === config.email) {
|
||||
next();
|
||||
} else {
|
||||
res.redirect('/login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = checkSession
|
||||
Reference in New Issue
Block a user