moshest / next-client-cookies

SSR and client support for cookies in Next.js 13 (app directory)
MIT License
136 stars 9 forks source link

Next.js now requires access to `cookies()` to be called asynchronously #22

Open mordechaim opened 3 hours ago

mordechaim commented 3 hours ago

The following code: https://github.com/moshest/next-client-cookies/blob/68439a612ab339307ff833cadd2ac8ff6c730ed5/src/server.tsx#L9

Triggers a warning on next@canary:

In route / a cookie property was accessed directly with `cookies().getAll()`. `cookies()` now returns a Promise and the return value should be awaited before accessing properties of the underlying cookies instance. In this version of Next.js direct access to `cookies().getAll()` is still supported to facilitate migration but in a future version you will be required to await the result. If this `cookies()` use is inside an async function await the return value before accessing attempting iteration. If this use is inside a synchronous function then convert the function to async or await the call from outside this function and pass the result in.

Rational

mordechaim commented 3 hours ago

The fix should be simple, since we are in a server component, mark the function with async and call the function with await