-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequireAuth.js
37 lines (34 loc) · 947 Bytes
/
requireAuth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module.exports = {
ensureAuth: function (req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
res.redirect(
"/login?returnURL=" +
req.originalUrl +
"&message=You must be logged in to access the page"
);
}
},
ensureLoggedIn: function (req, res, next) {
if (req.isAuthenticated()) {
res.redirect("/dashboard");
} else {
return next();
}
},
ensureAdmin: function (req, res, next) {
if (req.isAuthenticated() && req.user.site_admin === true) {
return next();
} else {
res.send("Page was not found on the server?");
}
},
ensureGuest: function (req, res, next) {
if (!req.isAuthenticated()) {
return next();
} else {
return next();
}
},
};