JaBa/dashboard/auth/CheckAuth.js

9 lines
368 B
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
module.exports = async (req, res, next) => {
2021-12-16 23:42:58 +05:00
if (req.session.user) return next();
else {
2021-12-10 21:39:54 +05:00
const redirectURL = ((req.originalUrl.includes("login") || req.originalUrl === "/") ? "/selector" : req.originalUrl);
const state = Math.random().toString(36).substring(5);
req.client.states[state] = redirectURL;
return res.redirect(`/api/login?state=${state}`);
};
};