workos / authkit-nextjs

The WorkOS library for Next.js provides convenient helpers for authentication and session management using WorkOS & AuthKit with Next.js.
MIT License
67 stars 18 forks source link

NextJS 15 canary async headers/cookies compatibility #104

Closed f1shy-dev closed 1 month ago

f1shy-dev commented 1 month ago
In route / a cookie property was accessed directly with `cookies().get('wos-session')`. `cookies()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
In route /ai-sdk-chat/[id] a header property was accessed directly with `headers().get('x-workos-middleware')`. `headers()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
In route /ai-sdk-chat/[id] a header property was accessed directly with `headers().get('x-workos-session')`. `headers()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

Latest NextJS canary beta is showing these errors, using AuthKit and getUser()

Likely a simple change that needs to be made inside authkit-nextjs?

PaulAsjes commented 1 month ago

Thanks for the report! We'll look into this. The fix should be easy enough, just want to make sure that awaiting that getter is backwards compatible with older versions of Next.

pdeva commented 1 month ago

This issue is preventing us from moving to Next 15

nirtamir2 commented 1 month ago

Now Next.js 15 is stable - so I think it's safe to change this and await the cookie: https://github.com/workos/authkit-nextjs/blob/7fa52f555fdad62a2e76579d6739e067acbfd059/src/session.ts#L105

Made a small PR for you to check https://github.com/workos/authkit-nextjs/pull/118

PaulAsjes commented 1 month ago

Thanks, we're working on this right now and hope to get a fix out today.

nirtamir2 commented 1 month ago

Thanks for the quick response! ❤️ So no need to patch-package 🎉

PaulAsjes commented 1 month ago

This has been released as v0.13.0!