04
Middleware + Dashboard Layout
Edge-level auth protection — replaces PrivateRoute.jsx entirely
Week 32–3 daysSecurity Critical
Phase Progress0/3 tasks · 0%
middleware.js — the most powerful file in Next.js
Runs at Vercel's edge network before any page loads. Unauthenticated users are redirected before the page even starts rendering.
Dashboard Layout
Create app/dashboard/layout.jsx — add 'use client', paste DashboardLayout
Delete PrivateRoute.jsx — middleware.js does this job better now
Replace <NavLink> — use usePathname() for active route detection
Gotcha: Middleware reads cookies, not localStorage. If your auth stores JWT in localStorage, middleware can't read it. Move to cookies.