stalniy / casl

CASL is an isomorphic authorization JavaScript library which restricts what resources a given user is allowed to access
https://casl.js.org/
MIT License
5.74k stars 257 forks source link

Unable to understand the implementation of CASL in nextjs App #909

Closed deepakshrma30 closed 2 months ago

deepakshrma30 commented 2 months ago

Describe the bug Unable to understand how can i define my route path which will be restricted for the subadmin

To Reproduce Steps to reproduce the behavior:

  1. Ability configuration (rules, detectSubjectType, etc)
  2. How do you check abilities

Expected behavior

const defineRulesFor = (role, subject) => {
  const data = window.localStorage.getItem('userData')
  const userData = JSON.parse(data)

  const { can, rules } = new AbilityBuilder(AppAbility)
  if (role === 'ADMIN') {
    can('manage', 'all')

  } else if (role === 'client') {
    can(['read'], 'acl-page')
  } else if (role === 'SUBADMIN') {

    can('read','amenities') // this thind does not work
  } else {
    can(['read', 'create', 'update', 'delete'], subject)
  }

  return rules

Screenshot 2024-05-06 160003 }

Interactive example (optional, but highly desirable) provide a link to the example from http://repl.it/, https://codesandbox.io/ or similar, so we can quickly test and provide feedback. Otherwise

CASL Version

@casl/ability - v

@casl/react - v

Environment:

stalniy commented 2 months ago

Did you look into examples? https://github.com/stalniy/casl-examples

stalniy commented 2 months ago

Close as this is not an issue with casl. Ask question on stackoverflow

I’ll create nests example at some point later

deepakshrma30 commented 1 month ago

thanks for the help