Skip to content

Commit 554a2c7

Browse files
authored
chore(website): update middleware page (#343)
In nextjs version 15, cookies is async https://nextjs.org/docs/app/api-reference/functions/cookies
1 parent d68a31e commit 554a2c7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

website/docs/define-actions/middleware.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export const authActionClient = actionClient
7575
// Define authorization middleware.
7676
// highlight-start
7777
.use(async ({ next }) => {
78-
const session = cookies().get("session")?.value;
78+
const cookieStore = await cookies();
79+
const session = cookieStore.get("session")?.value;
7980

8081
if (!session) {
8182
throw new Error("Session not found!");
@@ -265,4 +266,4 @@ export const actionClientWithMyMiddleware = actionClient.use(myMiddleware1).use(
265266

266267
An action defined using the `actionClientWithMyMiddleware` will contain `foo`, `baz` and `john` in its context.
267268

268-
\* Note that you can pass, **but not required to**, an object with three generic properties to the `createMiddleware()` function: `ctx` \[1\], `metadata` \[2\] and `serverError` \[3\]. Those keys are optional, and you should only provide them if you want your middleware to require **at minimum** the shape you passed in as generic. By doing that, following the above example, you can then access `ctx.foo` and `metadata.actionName` in the middleware you're defining, and by awaiting the `next` function you'll see that `serverError` is an object with the `message` property. If you pass a middleware that requires those properties to a client that doesn't have them, you'll get an error in `use()` method.
269+
\* Note that you can pass, **but not required to**, an object with three generic properties to the `createMiddleware()` function: `ctx` \[1\], `metadata` \[2\] and `serverError` \[3\]. Those keys are optional, and you should only provide them if you want your middleware to require **at minimum** the shape you passed in as generic. By doing that, following the above example, you can then access `ctx.foo` and `metadata.actionName` in the middleware you're defining, and by awaiting the `next` function you'll see that `serverError` is an object with the `message` property. If you pass a middleware that requires those properties to a client that doesn't have them, you'll get an error in `use()` method.

0 commit comments

Comments
 (0)