Favorieten toegevoegd aan de navigatiebalk en sidebar.
This commit is contained in:
+6
-5
@@ -1,17 +1,18 @@
|
||||
module.exports = function(req, res, next) {
|
||||
|
||||
|
||||
if (!req.session.userId) {
|
||||
|
||||
if (!req.session || !req.session.userId || !req.user) {
|
||||
if (req.originalUrl.startsWith("/api/")) {
|
||||
return res.status(401).json({ error: "Je bent niet ingelogd" });
|
||||
}
|
||||
|
||||
if (req.session && req.session.userId) {
|
||||
delete req.session.userId;
|
||||
}
|
||||
|
||||
req.flash("info", "Je sessie is verlopen. Log opnieuw in.");
|
||||
return res.redirect("/login");
|
||||
|
||||
}
|
||||
|
||||
|
||||
next();
|
||||
|
||||
};
|
||||
|
||||
+12
-8
@@ -4,17 +4,21 @@ require("../repositories/UserRepository");
|
||||
|
||||
module.exports = function userMiddleware(req, res, next) {
|
||||
|
||||
req.user = null;
|
||||
|
||||
if (req.session.userId) {
|
||||
|
||||
req.user =
|
||||
UserRepository.findById(
|
||||
req.session.userId
|
||||
);
|
||||
|
||||
if (!req.session || !req.session.userId) {
|
||||
return next();
|
||||
}
|
||||
|
||||
req.user = UserRepository.findById(req.session.userId);
|
||||
|
||||
next();
|
||||
if (!req.user) {
|
||||
delete req.session.userId;
|
||||
if (typeof req.session.destroy === "function") {
|
||||
return req.session.destroy(() => next());
|
||||
}
|
||||
}
|
||||
|
||||
return next();
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user