Next.js Discord

Discord Forum

Best library for auth with next.js?

Unanswered
American Chinchilla posted this in #help-forum
Open in Discord
Avatar
American ChinchillaOP
Hello, I am new to auth. I ahve heard of Clerk, Auth0 and next-auth. However I want to use one where I can really learn auth and not just use a black box where I dont understand what is happening behind the scenes. Any recommendations? I need one that allows different sign-in options like google or github, and two factor auth and ensure in every page the user's permissions.

33 Replies

Avatar
i like firebase auth
but develop your own auth if u want to learn
and integrate different sign in options from firebase
Avatar
Rainbow trout
https://lucia-auth.com/ does exactly that
Avatar
Great-tailed Grackle
lucia is getting depcrated next year i think its worth mentioning

https://github.com/lucia-auth/lucia/discussions/1707

still a solid option to learn
i recommend trying to roll your own auth first. refer to this nextjs docs:

https://nextjs.org/docs/app/building-your-application/authentication
Avatar
Rainbow trout
the package is getting deprecated, lucia itself isn't going anywhere
Avatar
Great-tailed Grackle
oh yeah mb, thought u mentioned luciaauth specifically 👍
Avatar
LaPerm
To be honest everytime I use an auth library I end up getting annoyed by the way it handles something and end up rolling my own. Lucia was good because it wasn't opinionated. Was reading about better-auth recently which looks good.
Avatar
what the problem with auth libraries?
Avatar
Miniature Pinscher
You seem to be conflating "auth libraries" with auth from scratch, with the latter being the only way to actually learn how auth works. As for recommended auth library, I'd suggest looking into Pocketbase. I've managed to create really neat SSR auth using it, of course also using its other features as well.
Avatar
American ChinchillaOP
@Miniature Pinscher thanks and yes i do want to learn auth from scratch but not from ground 0 similar to learning js and html but not learning how to build a framework since i dont want to reinvent the wheel
I would like an auth library to handle the different login such as google and github
But i would also like to implement from scratch sessions, or jwt for user id and cookies and encrypt passwords etc and user permission routes
I was thinking of using next-auth for this
But not sure if this is the best option or if should use somethings else
Avatar
Korat
Next-auth isn't good solution for credentials auth. And you doesn't gonna learn anything about sessions and so on. If you wanna learn something just roll your own auth with lucia-auth docs. Lucia just move from library to learning resource how to roll own auth.

If you want ready to go solution then use better-auth. I think Next-auth (authjs) is good only for handling providers auth like google, github not credentials.
Avatar
American ChinchillaOP
Yes i mean peovider
Is what i was looking for in an auth library
But il take a look at lucia
Do you think its worth learning how to build from scratch google or github login(Oauth)
Or stick to auth provider
Avatar
American ChinchillaOP
My goal is to learn backend as im new to it
And i know most jobs require knowledge of authentication etc
Avatar
Korat
It's always good to learn something new. But when you need only providers auth for your app I will personally use auth library for this. Providers auth is just a bunch of request and then code to provider that can be simplify via this wrapper https://arcticjs.dev/ (created by lucia creator).
Avatar
American ChinchillaOP
@Korat thanks!! Im reading google oauth docs and they say it best to use libraries with Oauth instead of doing it from scratch
Do you think it better learning how to use provider libraries like lucia and is not as important learning from scratch compared to learning sessions and authentication?
Avatar
Korat
It's good to know how thing works under the hood, like 0Auth and sessions. Lucia is switch to learning resource how you can roll your own auth. She even have nextjs examples on Github/Google OAuth and credentials auth with 2FA. I think you need to check diffrent libraries and try to roll your own auth and learn how thing works under the hood. I learn auth this way. And I think auth saases like clerk is skill issue for backend devs that doesn't know how to do auth.
Avatar
American ChinchillaOP
Thanks so much! Yeah i heard Oauth is hard
Avatar
American ChinchillaOP
@Korat i tried looking at lucia resources to learn such as OWASP Cheat Sheet Series but none of the resources are available 😦
Nevermind
Avatar
There is no specific best Library. Its a opinionated question.

For example, some personally prefer next auth,

and I prefer to build from scratch with this guide by lucia: https://lucia-next.pages.dev/