JS Auth helpers and Next.js integration production-ready?
I'm working on an older Supabase JS + Next project that used the 1.x supabase js client, and I'm seeing there's a new 2.x client along with these new auth-helpers and a Next.js specific library.
However, the Next.js library seems extremely beta and APIs are being deprecated (like
withPageAuth
) with no alternative documentation. I am questioning whether I should put in the effort to move to 2.x and use these new libraries when my 1.x version works just fine.
Any insight into where these newer 2.x-based libraries are at and whether they're stable enough to use at the moment?11 Replies
Hi @Maz there is a migration guide that shows the alternative for the methods that were removed https://supabase.com/docs/guides/auth/auth-helpers/nextjs#migration-guide, they were removed as the implementation of NextJS keeps on changing and it didn't make sense for us to have a higher order function to do what a developer can handle in their own app.
Supabase Auth with Next.js
Supabase Auth with Next.js
Authentication helpers for Next.js API routes, middleware, and SSR.
Thanks. One thing that's not clear to me is what these magic functions like
createServerSupabaseClient
are actually doing under the hood. Are they managing auth cookies? How do they replace the createClient
from the raw Supabase JS lib?There are no magic functions, they are managing auth cookies using the
supabase-js
library storage mechanism.Thanks, I need to read through the source. I don't love that there's one way to do it with the standard Supabase JS client, and then there's a very different API only when using Next. But I guess I just need to get used to it
You only require the auth-helpers if you are doing server side rendering, otherwise you can just use the standard supabase-js client. Also the auth-helpers are just making use of the standard supabase-js client while changing the storage mechanism. You could do this yourself but the helpers are there so you don't have to.
Yea I'm using both SSR and client-side based on the screen/UX flow. Before I was using
supabase.auth.api.getUserByCookie
and the other cookie-based routines so converting those over to this is what I'm navigating.That was a magical function as it only worked for nextjs or express based frameworks, this wasn't extendable enough to work with other SSR frameworks like Svelte Kit, Remix, etc.
Makes sense
I also waited to upgrade Nextjs and supabase v1 because of auth-helpers did not seem ready.. until
v0.5.1
hit, which with middleware, allowed me to combine my authorization SSR and extend middleware functionality to one place = neater+faster .
I would recommend upgrading if you can. Just make sure you read the supabase js migration and auth helpers 0.4 migration and 0.5 migration docs.
The only thing a bit flimsy is with the SessionContext
not refreshing on signin/signout, but I've gotten around it with using pure serverside redirectingIs there an issue open about that on GitHub? if not can you open one so we have it on our radar.
Yes https://github.com/supabase/auth-helpers/issues/370
It could be related to the Gotrue session Issue that Gary has created, but I’m not so sure after reading it.
GitHub
signOut does not clear session and useUser does not get latest unti...
Bug report Describe the bug Hello, I am currently upgrading from v1 to v2 and noticed some weird behaviors with auth-helpers and Nextjs after the exciting 0.5.1 update! I have followed the migratio...