Major bug fix
This commit is contained in:
18
drill-and-practice/middlewares/authMiddleware.js
Normal file
18
drill-and-practice/middlewares/authMiddleware.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const restrictedPaths = ["/quiz", "/topics"];
|
||||
|
||||
const authMiddleware = async (state, next) => {
|
||||
const user = await state.session.get("user");
|
||||
|
||||
if (
|
||||
!user &&
|
||||
restrictedPaths.some((path) =>
|
||||
context.request.url.pathname.startsWith(path)
|
||||
)
|
||||
) {
|
||||
context.response.redirect("/auth/login");
|
||||
} else {
|
||||
await next();
|
||||
}
|
||||
};
|
||||
|
||||
export { authMiddleware };
|
||||
Reference in New Issue
Block a user