Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isAdmin = ({ session }: { session: Session }) => Boolean(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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isAdmin = ({ session }: { session: Session }) => Boolean(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 }) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isAdmin = ({ session }: { session: Session }) =>
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