Provide `forbiddenBecause` message in `Can` child render function
Opened this issue · 0 comments
paulleonartcalvo commented
Is your feature request related to a problem? Please describe.
When using the Can
component, it is often desirable to inform the user, visually, why they cannot perform a certain action. However, it is verbose and cumbersome to surface the .because("...")
messages that one may define on their abilities. When you use Can
you have to:
- Write the condition into the props
- Write the condition again when either throwing a Forbidden error or just creating one to get the message
Describe the solution you'd like
Can
's child render function will accept a third argument (forbiddenBecause
), which will be the same string as outputted byForbiddenError.from(ability).unlessCan(...condition)?.message
.- It will be of type
string | undefined
.string
whenallowed
isfalse
, returning either the default error message or a defined rule message. It will beundefined
whenallowed
istrue
.
Describe alternatives you've considered (optional)
- Repeating the condition to get a Forbidden Error
- Using
getRelevantRulesFor
Additional context (optional)
None