Advanced authentication in NextJs using middleware & server actions @hamedbahram
Advanced authentication in NextJs using middleware & server actions  @hamedbahram
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
Advanced authentication in NextJs using middleware & server actionsThe new `useTransition` hook with 3 example usecasesUsing NextUI Components & Themes in NextJsUnlocking the Power of AI with Vercel SDK ft Nico AlbaneseBuild an ecommerce site using NextJS and SwellTanStack Start: Server Components Without the Mental GymnasticsLoading Skeleton for Search & Pagination in NextJs 13 Movie AppAnimating Background Gradients using Framer MotionTen UI Libraries, Components, and Tools I UseSync Clerk Data to Your Database Using WebhooksReact Resizable PanelsIn conversation with Colby Fayock from Cloudinary
Hamed Bahram |

Advanced authentication in NextJs using middleware & server actions

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER