Next.js Discord

Discord Forum

Difficulty initialising next-auth in App Router

Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Australian Freshwater CrocodileOP
Hi, I am having difficulty following the NextAuth.js docs on implementing NextAuth on NextJS projects using the App Router.

I am new to NextAuth and have only ever worked with App Router. I understand Page Router was born before App Router but the docs are still largely tailored to Page Router with minimal references/guidance on App Router initialisation.

It feels like I need to understand Page Router & NextAuth relationship before I can modify and apply it to App Router. There's nothing wrong with knowing the different implementations but it is cumbersome when you only have need for one implementation. For example, the top code snippet is clear it refers to App Router, but every other code snippet is of Page Router and is unclear of what modifications to make if using App Router.

I would rather see some documentation strictly tailored to App Router to understand NextAuth in this context better before I need to understand it in Page Router where I have no current use for it. Is anyone aware of such documentation?

2 Replies

Ok the problem with that is that next-auth is now becoming something that will be framework agnostic. So what you need to shift you mentality to is checking if the component that is holding and running the next auth script is a server or client component and work from there accordingly.
Sun bear
This might not answer your question but I highly suggest dropping next-auth in favour of lucia.

NextAuth makes authentication a nightmare and even intentionally makes it harder to implement some things such as credentials auth. Their docs are terrible, level of abstraction is bad and it is hard to get it to work properly.

I have worked on 3 smaller projects of mine and always dropped them on the authentication part since it was too hard to get working correctly.

On my next project I have decided switch it up and try lucia. It took me about an hour to get it working properly and the entire process was a breeze, dare I say even fun.

I have never seen better docs than the ones lucia has. Everything was easy to find, all the important security aspects were mentioned, the getting started road-map was good and all minimal code examples were working out of the box.

There is also a discord server if you need any help with debugging or get stuck somewhere.

I just want to say for the last thing is that I am not in association with lucia team and the library was just that good that I needed to write this in hopes of saving you from the hellish nightmare called NextAuth.

Check out [lucia auth, next.js app router guide.](https://lucia-auth.com/getting-started/nextjs-app)