redirect nicely depending on authorized or not
This commit is contained in:
parent
2e79a1fadd
commit
70f9118d82
4 changed files with 23 additions and 3 deletions
10
src/middlewares/redirectHomeIfAuthorized.js
Normal file
10
src/middlewares/redirectHomeIfAuthorized.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
const sessionService = require('../services/sessionService');
|
||||
|
||||
async function redirectHomeIfAuthorized(req, res, next) {
|
||||
if (await sessionService.isSessionAuthorized(req.cookies.sessionUuid)) {
|
||||
return res.redirect('/home');
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = redirectHomeIfAuthorized;
|
||||
|
|
@ -2,7 +2,7 @@ const sessionService = require('../services/sessionService');
|
|||
|
||||
async function redirectIfNotAuthorizedMiddleware(req, res, next) {
|
||||
if (!(await sessionService.isSessionAuthorized(req.cookies.sessionUuid))) {
|
||||
return res.redirect('/');
|
||||
return res.redirect('/login');
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue