Course lesson
Refresh Session Cookie for Next.js Server Components with Middleware
Server Components cannot set cookies in the Next.js App Router. In this lesson, we implement middleware to refresh expired Supabase sessions.
- Duration
- 2 min
- Access
- Free
- Transcript
- Retained from source evidence
Server Components cannot set cookies in the Next.js App Router. In this lesson, we implement middleware to refresh expired Supabase sessions.
Middleware runs immediately before the route is loaded. By using it to refresh our user's session, we ensure it is valid by the time it loads the Server Component and attempts to fetch data from Supabase.
Code Snippets
Refresh expired sessions
supabase.auth.getSession();