7
9 Comments

Authentication in Next.js

I'm working on a project and am considering what auth solution to use. I could roll my own using API routes, Next Auth, Auth0, or something else. I'm leaning towards Auth0 since I'll need SAML/LDAP in the future for larger organizations. For the moment, I need email and social sign ups. I already have a Postgres database so Next Auth may be faster to set up.

What would you recommend? I'm especially curious your thoughts on Next Auth vs Auth0.

on August 12, 2021
  1. 3

    I would definitely use something like Auth0, Next Auth or similar. But in any case I would opt for connecting to these services using plain OpenID Connect.
    Don't fall into the trap of using vendor specific API's, unless you really have to.

    As long as you connect to these services using plain OpenID Connect client libraries, migrating in the future should be relatively easy.
    And the big advantage of starting with plain OpenID Connect is that you don't have to decide what authentication service to use right now.

    1. 1

      Interesting idea. I'm not too familiar with OpenID Connect but will do some research. Definitely like the idea of having that layer of separation to make refactoring easier in the future

  2. 3

    My super quick advice is that switching auth after you've already started to onboard is going to be a nightmare.

    It is probably worth starting right away with whatever you think you'll use in a long run.

    That said, are you ready for the costs of Auth0 beyond the free tier? It gets pricey fast.

    1. 1

      That's good advice. And since it's a client project, I'll need to weight the time to development, features, and cost with them but I think price isn't a huge issue.

  3. 2

    If you look for something quick and dirty ( like an mvp or a toy project), it doesn't get simplier than using firabse authentification. But you will get locked in to the vendor.
    Otherwise NextAuth is the best way in my opinion, as it is simple enough, has good documentation and you can change vendors easily.

  4. 2

    Only got one thing to say: Def don't build your own

    Rest has already been mentioned

    1. 1

      Yeah, having implemented it myself a few times for toy projects, definitely going with something else. Either open-source or a service which means I guess my main question is really Next Auth vs. Auth0

  5. 1

    Hey - We have published a blog on how to do passwordless authentication with nextJS.

    I hope it would be helpful for someone in the community looking for no password solution:
    https://mojoauth.com/blog/how-to-implement-passwordless-authentication-in-next.js/

  6. 1

    Hi!! ButterCMS just published a blog post on a guide for how to authenticate Next.js with NextAuth! You can read it here: https://buttercms.com/blog/nextjs-authentication-tutorial/