This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
authapp/authserver/middlewares/authMiddleware.js
AndrewTrieu c9f31e5c8a First commit
2023-04-21 13:17:50 +03:00

18 lines
372 B
JavaScript

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 };