get-convex / convex-auth

Library for built-in auth
https://labs.convex.dev/auth
55 stars 17 forks source link

NextJS 15 support #113

Open mez opened 1 month ago

mez commented 1 month ago

Just tried to update to Next15, the Async Request APIs breaking changes did break convexAuth specifically cookie and token requesting area.

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

To reproduce, just update to Next 15 while using convexAuth.

thomasballinger commented 1 month ago

sounds like https://nextjs.org/blog/next-15#async-request-apis-breaking-change

AndrewDonelson commented 2 weeks ago

wow :( ETA on this? one of my project was giving me issues and i upgraded node, npm and next 14->15 and now none of my projects work. I really do not want to go back to the previous versions and ALL of my apps use convex + convex auth

thomasballinger commented 1 week ago

Here's a Next.js 15 demo using a branch of this library (published as @convex-dev/auth@0.0.75-alpha.1) and a new convex alpha (convex@1.17.1-alpha.1): https://github.com/get-convex/convex-auth-test-next15

These are experimental builds, if you try them please let us know how they are!

Before merging https://github.com/get-convex/convex-auth/pull/118 I'd like to get some feedback.

JohnKesko commented 1 week ago

@thomasballinger Just tried it out, here is some feedback. (Note I am also using @auth/core": "^0.37.4)

So this installs fine while also having @auth/core: "@convex-dev/auth": "0.0.75-alpha.1"

But updating "convex": "^1.17.0" to "convex": "1.17.1-alpha.1" does not work in same context with @auth/core. I guess that's because @convex-dev/auth@0.0.75-alpha.1 depends on @auth/core@"^0.36.0" ? Anyway, so I downgraded auth/core to "^0.36.0" and install was fine and then updated core to 0.37, everything fine here.

Now I tested login to Google/Github and the error messages as OP described was gone - however, routing didn't work. I have a dynamic route to app/user/[[...userId]] after login but I was never redirected. So I thought my middleware was bugging and just copy-pasted yours from the example but it still didn't work. So now I just renamed it to _middleware.ts and login and routing worked just fine! Adding back middleware.ts, routing stopped working.

thomasballinger commented 1 week ago

@JohnKesko thank you! Great this is really helpful for scoping this work, appreciate the investigation.

thomasballinger commented 5 days ago

@JohnKesko could you share your middleware.ts file? With simple middleware I can't reproduce this.

JohnKesko commented 3 days ago

@thomasballinger

Nevermind. All works just fine now even with middleware.ts as in your example. The reason was I didn't have my root layout wrapped in <ConvexAuthNextjsServerProvider>, totally missed that 🤦

thomasballinger commented 3 days ago

Great to hear! Sounds like we're closer to releasing this, still want to let it bake a bit.