I'm starting a new project which requires me to implement authentication for both accessing page and API. I'm developing it using Next.js. So, my question is, should I use this library or the auth0-react? I've given both a quick PoC and they seem to be working at least for what I was aiming at.
Is there any advantage that one gives over the other?
Thank you :)
From my understanding, the reason this package (nextjs-auth0) exists is to allow you know whether the user is authenticated when rendering the page on the server, which saves the client having to initially load the page and then make an API call with the session cookie.
This diagram (pulled from Auth0's guide) explains further what is happening with the nextjs-auth0 package:

@lunchboxav You should read this article carefully: https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/ It's the mother lode.
You should absolutely use this library with next.js! -- it fully enables server-side auth using a cookie-based system. The react one is purely frontend.
FYI the only true limitation of this library we've found after using it is that if you update user metadata on Auth0 it will not be synced back to the cookie, so it's difficult to implement user-pref features with it. In contrast their 2 frontend-facing libs (js, react) are set up to do silent re-authentication which pulls down the latest user prefs.
Other than that, and the fact that this is currently on ice as they upgrade their ecosystem of libs internally, this library is a very powerful approach. Even though SSG pages won't be able to use server-side auth, it's easy enough to call an api route that loads the logged-in user just after first render which is usually just a split second since it's cached, see my example here: https://github.com/auth0/nextjs-auth0/issues/132#issuecomment-682112788
the fact that this is currently on ice as they upgrade their ecosystem of libs internally
Sorry a little OT, but is there more information about this somewhere?
@mosesoak Ref the above post, do you have any more info regarding auth0's upgrade of their lib ecosystem? Or a link to some info? 馃槉
Hi everyone, we have included the answer to this question in the README of the new beta version. Please check it out here.
Most helpful comment
@lunchboxav You should read this article carefully: https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/ It's the mother lode.
You should absolutely use this library with next.js! -- it fully enables server-side auth using a cookie-based system. The react one is purely frontend.
FYI the only true limitation of this library we've found after using it is that if you update user metadata on Auth0 it will not be synced back to the cookie, so it's difficult to implement user-pref features with it. In contrast their 2 frontend-facing libs (js, react) are set up to do silent re-authentication which pulls down the latest user prefs.
Other than that, and the fact that this is currently on ice as they upgrade their ecosystem of libs internally, this library is a very powerful approach. Even though SSG pages won't be able to use server-side auth, it's easy enough to call an api route that loads the logged-in user just after first render which is usually just a split second since it's cached, see my example here: https://github.com/auth0/nextjs-auth0/issues/132#issuecomment-682112788