Protected path with auth π§ -- Question
macarthuror opened this issue Β· comments
Arturo Ortega commented
Hello everyone π
Is it possible to protect a path in the public directory?
Right now I'm developing a project using sessions for the auth, but I want to protect the resources for the no authenticated people.
This is my code rigth now
app.use(mount('/assets', serve(__dirname + '/../public')))
I'm trying to implement a middleware before serve the files but all what I tried failed.
Does anyone have some idea to solve it ?
Thanks π
Arturo Ortega commented
Allrady resolved π
To verify I used a global middleware who checks when someone want to get the files.
app.use((ctx, next) => {
const { path } = ctx
if (path.includes('/assets/private')) {
if (!isAuth){
ctx.throw(401)
return
}
next()
} else {
next()
}
})