Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await cookies #851

Closed
Dakuan opened this issue Nov 20, 2024 · 6 comments
Closed

await cookies #851

Dakuan opened this issue Nov 20, 2024 · 6 comments
Assignees
Labels
enhancement To make it better

Comments

@Dakuan
Copy link

Dakuan commented Nov 20, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @logto/next@3.7.1 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@logto/next/lib/server-actions/client.js b/node_modules/@logto/next/lib/server-actions/client.js
index 09129a6..d44bdd9 100644
--- a/node_modules/@logto/next/lib/server-actions/client.js
+++ b/node_modules/@logto/next/lib/server-actions/client.js
@@ -64,13 +64,13 @@ class LogtoClient extends LogtoNextBaseClient {
             encryptionKey: this.config.cookieSecret,
             cookieKey: `logto:${this.config.appId}`,
             isSecure: this.config.cookieSecure,
-            getCookie: (...args) => {
-                return cookies().get(...args)?.value ?? '';
+            getCookie: async (...args) => {
+                return (await cookies()).get(...args)?.value ?? '';
             },
-            setCookie: (...args) => {
+            setCookie: async (...args) => {
                 // In server component (RSC), it is not allowed to modify cookies, see https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options.
                 if (!ignoreCookieChange) {
-                    cookies().set(...args);
+                    (await cookies()).set(...args);
                 }
             },
         });

This issue body was partially generated by patch-package.

@charIeszhao
Copy link
Member

@wangsijie Do you think the await is necessary? Are cookies async?

@Dakuan
Copy link
Author

Dakuan commented Nov 21, 2024

yes

[Error: Route "/" used `cookies().get('logto:jwtsdep1memhjojskp0fk')`. `cookies()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis]

@Dakuan
Copy link
Author

Dakuan commented Nov 21, 2024

terminal looks like this in next 15 😂

image

@wangsijie
Copy link
Contributor

#836

@kdy1
Copy link

kdy1 commented Nov 22, 2024

Next.js maintainer & logto (personal) user here. This is the change in next@15

See https://nextjs.org/docs/app/building-your-application/upgrading/version-15#async-request-apis-breaking-change for more details.

@simeng-li simeng-li added the enhancement To make it better label Nov 26, 2024
@wangsijie
Copy link
Contributor

duplicate of #836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement To make it better
Development

No branches or pull requests

5 participants