routing-controllers: Bug:throw error in authorizationChecker

If the authorizationChecker is a function that returns a rejected Promise, the client will not be able to respond.

my code:

authorizationChecker: async (action: Action, roles: string[]) => {
	let user = action.request.user;
	if (!user) throw new UnauthorizedError(); //bug is here

	if (user && !roles.length)
		return true;
	if (user && roles.find(role => user.roles.indexOf(role) !== -1))
		return true;

	return false;
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (21 by maintainers)

Most upvoted comments

We still need to fix it for Koa, but we can track that in the PR

I just kept it the same way as we check for errors in other parts of the app.

Your code is smaller, but wrapping checkResult in a Promise seems like a too big trade off on performance.