Skip to content

Commit 80791c0

Browse files
authored
docs: cookie clear and has alignment (#86788)
Closes: #86778
1 parent 96ae01c commit 80791c0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

docs/01-app/03-api-reference/04-functions/cookies.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ The following methods are available:
3838
| `has('name')` | Boolean | Accepts a cookie name and returns a boolean based on if the cookie exists. |
3939
| `set(name, value, options)` | - | Accepts a cookie name, value, and options and sets the outgoing request cookie. |
4040
| `delete(name)` | - | Accepts a cookie name and deletes the cookie. |
41-
| `clear()` | - | Deletes all cookies. |
4241
| `toString()` | String | Returns a string representation of the cookies. |
4342

4443
### Options
@@ -80,7 +79,7 @@ When working with cookies in Server Components, it's important to understand tha
8079
- **Reading cookies** works in Server Components because you're accessing the cookie data that the client's browser sends to the server in the HTTP request headers.
8180
- **Setting cookies** cannot be done directly in a Server Component, even when using a Route Handler or Server Action. This is because cookies are actually stored by the browser, not the server.
8281

83-
The server can only send instructions (via `Set-Cookie` headers) to tell the browser to store cookies - the actual storage happens on the client side. This is why cookie operations that modify state (`.set`, `.delete`, `.clear`) must be performed in a Route Handler or Server Action where the response headers can be properly set.
82+
The server can only send instructions (via `Set-Cookie` headers) to tell the browser to store cookies - the actual storage happens on the client side. This is why cookie operations that modify state (`.set`, `.delete`) must be performed in a Route Handler or Server Action where the response headers can be properly set.
8483

8584
## Understanding Cookie Behavior in Server Actions
8685

docs/01-app/03-api-reference/04-functions/next-request.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ request.cookies.has('experiments')
6767

6868
### `clear()`
6969

70-
Remove the `Set-Cookie` header from the request.
70+
Remove all cookies from the request.
7171

7272
```ts
7373
request.cookies.clear()

docs/01-app/03-api-reference/04-functions/next-response.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ response.cookies.getAll('experiments')
5151
response.cookies.getAll()
5252
```
5353

54+
### `has(name)`
55+
56+
Given a cookie name, return `true` if the cookie exists on the response.
57+
58+
```ts
59+
// Given incoming request /home
60+
let response = NextResponse.next()
61+
// Returns true if cookie exists, false if it does not
62+
response.cookies.has('experiments')
63+
```
64+
5465
### `delete(name)`
5566

5667
Given a cookie name, delete the cookie from the response.

0 commit comments

Comments
 (0)