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

Access Control Not working #285

Open
ranaharoon3222 opened this issue Aug 14, 2021 · 0 comments
Open

Access Control Not working #285

ranaharoon3222 opened this issue Aug 14, 2021 · 0 comments

Comments

@ranaharoon3222
Copy link

Bug report

Describe the bug

am using keystone-5-app and access control not working properly. am using below code

A clear and concise description of the bug.
Only access control not working as expected

To Reproduce

i provide code below
Steps to reproduce the behaviour. Please provide code snippets or a repository:

Expected behaviour

user can crud their own resources
A clear and concise description of what you expected to happen.

// Access control functions
const isAdmin = ({ authentication: { item: user } }) =>
  Boolean(user && user.isAdmin);
const isLoggedIn = ({ authentication: { item: user } }) => Boolean(user);
const isOwner = ({ authentication: { item: user } }) => {
  if (!user) {
    return false;
  }
  return { id: user.id };
};

const isAdminOrOwner = (auth) => {
  console.log(auth);
  const isAdmin = access.isAdmin(auth);
  const isOwner = access.isOwner(auth);
  return isAdmin ? isAdmin : isOwner;
};

const access = { isAdmin, isLoggedIn, isOwner, isAdminOrOwner };

keystone.createList('Post', {
  fields: PostSchema.fields,
  // List-level access controls
  access: {
    read: true,
    update: access.isAdminOrOwner,
    create: access.isLoggedIn,
    delete: access.isAdminOrOwner,
    auth: true,
  },
});

Screenshots

If applicable, add screenshots to help explain your problem.

System information

windows 10

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]

Additional context

Add any other context about the problem here.

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

2 participants