Skip to content

Commit

Permalink
Update auth-and-access-control.md (keystonejs#9039)
Browse files Browse the repository at this point in the history
  • Loading branch information
dagrinchi authored Feb 25, 2024
1 parent c907dc0 commit 5df5be1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/pages/docs/guides/auth-and-access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ type Session = {
We can now set up **operation** access control to restrict the **create**, **update** and **delete** operations to authenticated users with the `isAdmin` checkbox set:
```ts
const isAdmin = ({ session }: { session: Session }) => session?.data.isAdmin;
const isAdmin = ({ session }: { session: Session }) => Boolean(session?.data.isAdmin);

const Post = list({
access: {
operation: {
query: isAdmin,
create: isAdmin,
update: isAdmin,
delete: isAdmin,
Expand Down Expand Up @@ -432,11 +433,14 @@ When you need it, you can call `context.sudo()` to create a new context with ele
For example, we probably want to block all public access to querying users in our system:

```ts
const isAdmin = ({ session }: { session: Session }) => session?.data.isAdmin;
const isAdmin = ({ session }: { session: Session }) => Boolean(session?.data.isAdmin);

const Person = list({
access: {
query: isAdmin,
create: isAdmin,
update: isAdmin,
delete: isAdmin
},
fields: {
// see above
Expand Down Expand Up @@ -515,7 +519,7 @@ const isUser = ({ session }: { session: Session }) =>
// Validate the current user is an Admin
const isAdmin = ({ session }: { session: Session }) =>
session?.data.isAdmin;
Boolean(session?.data.isAdmin);
// Validate the current user is updating themselves
const isPerson = ({ session, item }: { session: Session, item: PersonData }) =>
Expand All @@ -528,7 +532,9 @@ const isAdminOrPerson = ({ session, item }: { session: Session, item: PersonData
const Person = list({
access: {
operation: {
query: isAdmin,
create: isAdmin,
update: isAdmin,
delete: isAdmin,
},
item: {
Expand Down

0 comments on commit 5df5be1

Please sign in to comment.