-
Notifications
You must be signed in to change notification settings - Fork 399
Fix/auth decorator status code #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/auth decorator status code #178
Conversation
sync upstream
403 with roles and 401 without
src/driver/express/ExpressDriver.ts
Outdated
|
||
} else { | ||
next(); | ||
} | ||
}); | ||
} else { | ||
if (!checkResult) { | ||
this.handleError(new AccessDeniedError(action), actionMetadata, action); | ||
this.handleError((actionMetadata.authorizedRoles.length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all these code blocks become messy... maybe we should avoid using ternary if and beatify code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ternary is faster, so if the libs want's to be fast, this should stay with other tail call optimizations 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if the libs want's to be fast
I see you need time to heal from the traumatic experience of that conversation 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only traumatic thing is the hypocrisy:
Promise.resolve
removes half on duplicated code block but it's slower, so we stick with messy code because "its important to make it performant as we can"- now "all these code blocks become messy", so we should remove ternary and tail call optimization to "beatify code"
So please be consistent - peformance at any cost or readable and maintainable code 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@19majkel94 you should investigate a bit how Promise.resolve
actually works, its not as simple as let vs const. We make decisions based on pros and cons of everything, its impossible to be consistent in everything, so make judging based on each scenario individually.
} else { | ||
if (!checkResult) { | ||
this.handleError(new AccessDeniedError(action), actionMetadata, action); | ||
const handleError = (result: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do you like this one?
src/driver/express/ExpressDriver.ts
Outdated
this.handleError(new AccessDeniedError(action), actionMetadata, action); | ||
const handleError = (result: any) => { | ||
if (!result) { | ||
return this.handleError(( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiline params this way do not look good, simplify this. extract error class in a separate variable if needed
everyone thinks its good to merge (not only performance and code style considerations 😆 ) ? |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Let
@Authorized()
raising401
and@Authorized("some_role")
raising403
.