Uploaded May 2023 | Updated December 2026, 3 hours ago
In this video, we will implement authentication using middleware in NextJs 13 and the NextAuth package. We'll also update the session on the client side using Server Actions and the new `update` function from NextAuth.
UPDATE: A safe way to pass the user data to the form action is to use the session data instead of the hidden form field. I've updated the source code in Github to reflect this.
ππΌ The Ultimate NextJs Course
π hamedbahram.io/courses/nextjs
ππΌ Source code (check the `advanced` branch)
π github.com/HamedBahram/next-auth-demo
ππΌ NextAuth β updating the session
π next-auth.js.org/getting-started/client#updating-the-session
ππΌ NextAuth β using middleware
π next-auth.js.org/configuration/nextjs#middleware
ππΌ NextJs documentation β middleware
π nextjs.org/docs/app/building-your-application/routing/middleware
Chapters
0:00 Intro
1:20 Project outline
3:40 Adding a database adapter
6:00 Profile page
9:00 Updating the session
13:50 Server actions
19:08 Using a middleware
25:34 Outro
In this video, we will implement authentication using middleware in NextJs 13 and the NextAuth package. We'll also update the session on the client side using Server Actions and the new `update` function from NextAuth.
UPDATE: A safe way to pass the user data to the form action is to use the session data instead of the hidden form field. I've updated the source code in Github to reflect this.
ππΌ The Ultimate NextJs Course
π hamedbahram.io/courses/nextjs
ππΌ Source code (check the `advanced` branch)
π github.com/HamedBahram/next-auth-demo
ππΌ NextAuth β updating the session
π next-auth.js.org/getting-started/client#updating-the-session
ππΌ NextAuth β using middleware
π next-auth.js.org/configuration/nextjs#middleware
ππΌ NextJs documentation β middleware
π nextjs.org/docs/app/building-your-application/routing/middleware
Chapters
0:00 Intro
1:20 Project outline
3:40 Adding a database adapter
6:00 Profile page
9:00 Updating the session
13:50 Server actions
19:08 Using a middleware
25:34 Outro










