First commit
This commit is contained in:
17
authserver/middlewares/authMiddleware.js
Normal file
17
authserver/middlewares/authMiddleware.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const restrictedPaths = ["/index"];
|
||||
|
||||
const authMiddleware = async (context, next) => {
|
||||
const user = await context.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