Skip to content
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

Provide forbiddenBecause message in Can child render function #972

Open
paulleonartcalvo opened this issue Sep 19, 2024 · 0 comments
Open

Comments

@paulleonartcalvo
Copy link

paulleonartcalvo commented Sep 19, 2024

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:

  1. Write the condition into the props
  2. 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 by ForbiddenError.from(ability).unlessCan(...condition)?.message.
  • It will be of type string | undefined. string when allowed is false, returning either the default error message or a defined rule message. It will be undefined when allowed is true.

Describe alternatives you've considered (optional)

  • Repeating the condition to get a Forbidden Error
  • Using getRelevantRulesFor

Additional context (optional)
None

@paulleonartcalvo paulleonartcalvo changed the title Provide forbidden message in Can child render function Provide forbiddenBecause message in Can child render function Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant