You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tachijs's controllers are just representation of express routers. So, for now, tachijs apply controller middlewares to their each router directly.
This causes the below problem:
// A middleware which check if current user is signed inconstuserOnly: express.RequestHandler=(req,res,next)=>{if(req.user==null){next(thrownewError('You have to sign in'))return}next()}
@controller('/posts',[userOnly])classUserOnlyPostController{// ...some methods just for signed in user, like writing, editing and deleting Post}
@controller('/posts')classPublicPostController{// ...some methods for everyone like listing articles and reading a specific article.}tachijs({controllers: [UserOnlyPostController,PublicPostController]}).listen(8000)
is identically same to
constapp=express()constuserOnlyPostRouter=express.Router()userOnlyPostRouter.get(...)constpublicPostRouter=express.Router()publicPostRouter.get(...)// Every request have to pass userOnly middlewareapp.use('/posts',userOnly,userOnlyPostRouter)// So if current user isn't signed in, he cannot reach `publicPostRouter`app.use('/posts',publicPostRouter)app.listen(8000)
So userOnly middleware is applied the both controllers.
I think this should make people confusing. So we have to change the behavior that controller middlewares are applied to their controller only.
It should be really easy to fix because all we have to do is apply controller middlewares for each route just before applying method middlewares.
Tachijs's controllers are just representation of express routers. So, for now, tachijs apply controller middlewares to their each router directly.
This causes the below problem:
is identically same to
So
userOnly
middleware is applied the both controllers.I think this should make people confusing. So we have to change the behavior that controller middlewares are applied to their controller only.
It should be really easy to fix because all we have to do is apply controller middlewares for each route just before applying method middlewares.
The text was updated successfully, but these errors were encountered: