auth-helpers: createMiddlewareSupabaseClient does not return the Session in Next.js middleware.
This boilerplate code does not currently work: https://supabase.com/docs/guides/auth/auth-helpers/nextjs#auth-with-nextjs-middleware, with createMiddlewareSupabaseClient writing this error to terminal:
Failed to parse cookie string: [Error: The edge runtime does not support Node.js 'buffer' module. Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime]
In my project, which is currently using the most basic boilerplate from the docs and Auth UI, I can confirm that the session is being created on login, stored in a cookie, and accessible by other means such as useUser.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 34 (11 by maintainers)
I’m looking into using
joseas a dependency instead ofjs-base64. My initial tests shows there are no warnings when trying to run the build, but I need to do more test to make sure that the correct values are being returned from the token and to also make sure that the issue from #487 doesn’t return with this change. I will keep everyone updated on this thread if all tests go well and when a new release goes out. I’m still waiting to hear from the Vercel team but this will be a more immediate fix I think.I’m closing this one out as I’ve published a new version that uses
joseand it also seems that Vercel has fixed Buffer in NextJS now.@nico-bachner the dependency we are using has
Bufferin it, but if the server you are using doesn’t support Buffer it falls back to its own implementation. I reached out to the Vercel team about this and they mentioned to me that Vercel Edge Runtime now supportsBufferand the latest NextJS works fine with buffer. However upon my test with a new NextJS project while doing the build step I get warnings aboutBufferbeing used in the dependency we are using, these warnings are to do with not even the use ofBufferbut to check ifBufferis available in the first place. I created a test repo showing the warnings and asked the Vercel team to look into it but I haven’t heard back from them as yet.https://vercel.com/changelog/improved-node-js-compatibility-for-edge-middleware-and-edge-functions
I also have this issue when the cookie token is malformed/invalid format.
@j1-dev @aleix10kst @Reikon95 If you’re having the issue that was fixed it means Vercel/NextJS has changed something again. The issue isn’t with the auth-helpers but with NextJS. You should open an issue on their repository.
You seem to be on the money with this one. The library relies on Buffer:
Buffer is not explicitly imported in the library’s source, which may have caused the confusion.
https://nodejs.dev/en/api/v19/buffer/
I’m experiencing this as well. Worked fine up until 0.5.8
Worked when I updated next.js and auth-helpers-nextjs
@silentworks confirming the error went away for me with Next 13.3 and auth-helpers-nextjs at 0.5.9
Until someone provides a reproducible codebase with this, there isn’t much we can do. I only get a warning when using the latest version of auth-helpers, it doesn’t stop the function from working.
Also adding comments with +1 aren’t very helpful or useful.
0.5.8 doesn’t work with next 13.3
+1 help out the NextJS gang
+1 Confirmed that it breaks at 0.5.9. Using 0.5.8 as @mryechkin suggested until it is fixed.