You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/local-api/access-control.mdx
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,9 @@ desc: Learn how to implement and enforce access control in Payload's Local API o
6
6
keywords: server functions, local API, Payload, CMS, access control, permissions, user context, server-side logic, custom workflows, data management, headless CMS, TypeScript, Node.js, backend
7
7
---
8
8
9
-
## Understanding Access Control in Local API Operations
10
-
11
9
In Payload, local API operations **override access control by default**. This means that operations will run without checking if the current user has permission to perform the action. This is useful in certain scenarios where access control is not necessary, but it is important to be aware of when to enforce it for security reasons.
12
10
13
-
### **Default Behavior: Access Control Skipped**
11
+
### Default Behavior: Access Control Skipped
14
12
15
13
By default, **local API operations skip access control**. This allows operations to execute without the system checking if the current user has appropriate permissions. This might be helpful in admin or server-side scripts where the user context is not required to perform the operation.
16
14
@@ -27,12 +25,12 @@ const test = await payload.create({
27
25
})
28
26
```
29
27
30
-
### **Respecting Access Control**
28
+
### Respecting Access Control
31
29
32
-
If you want to **respect access control** and ensure that the operation is performed only if the user has appropriate permissions, you need to explicitly pass the `user` object and set the `overrideAccess` option to `false`.
30
+
If you want to respect access control and ensure that the operation is performed only if the user has appropriate permissions, you need to explicitly pass the `user` object and set the `overrideAccess` option to `false`.
33
31
34
-
-**`overrideAccess: false`**: This ensures that access control is **not skipped** and the operation respects the current user's permissions.
35
-
-**`user`**: Pass the authenticated user context to the operation. This ensures the system checks whether the user has the right permissions to perform the action.
32
+
-`overrideAccess: false`: This ensures that access control is **not skipped** and the operation respects the current user's permissions.
33
+
-`user`: Pass the authenticated user context to the operation. This ensures the system checks whether the user has the right permissions to perform the action.
Copy file name to clipboardExpand all lines: docs/local-api/server-functions.mdx
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ In Next.js, **server functions** (previously called **server actions**) are spec
19
19
20
20
Use server functions whenever you need to call Local API operations from the frontend. Since the Local API is only accessible from the backend, server functions act as a secure bridge, eliminating the need to expose additional API endpoints.
21
21
22
-
## Examples: Using Local API from Server Functions
22
+
## Examples
23
23
24
24
All Local API operations can be used within server functions, allowing you to interact with Payload's backend securely.
25
25
@@ -63,7 +63,7 @@ export async function createPost(data) {
63
63
}
64
64
```
65
65
66
-
Now, let's look at how to call the \`createPost\` function we just created from the frontend in a React component when a user clicks a button:
66
+
Now, let's look at how to call the `createPost` function we just created from the frontend in a React component when a user clicks a button:
67
67
68
68
```ts
69
69
'use client';
@@ -123,7 +123,7 @@ export async function updatePost(id, data) {
123
123
}
124
124
```
125
125
126
-
Here is how you would call the \`updatePost\` function from a frontend React component:
126
+
Here is how you would call the `updatePost` function from a frontend React component:
0 commit comments