A long weekend with Next.js and NextAuth

2024-04-01

I spent a long weekend building a new project with Next.js and NextAuth.

Pretty simple requirements:

  • Sign in a user with Ory Network
  • Continue in the Next.js app (v14, App Router implementation) once authenticated

Lets just say I understand why frontend developers drink...

Ory

Ory only currently has docs for Next.js 13 and Pages Router, without support for App Router. I spent some time trying to get it to work with App Router, but ultimately had to bail out of the implementation and decided to look at a standard OAuth2 implementation.

NextAuth + OAuth2

I had previously played around with NextAuth and decided to look at it for this simple project. Within the first 5 minutes I was confused - The docs are a mix of their v4 implementation and their new v5 implementation (which was now renamed to auth).

Interesting, there wasn't a clear OAuth2 provider example, and mixed implementation between App Router and Pages Router.

Why is this so hard?

Back to the engine room for me.