Fixing AuthGuard Navigation, 401 Handling, and Sales‑Pipeline FK in a Next.js + NestJS Monorepo
TL;DR: I replaced the unreliable router.replace() in AuthGuard with a proper redirect using Next 13’s redirect() helper and added explicit 401 handling on the dashboard. I also corrected a foreign‑key typo in the sales‑pipeline table and wired the visual relationship between Properties and Pipeline in the API. Both changes removed hidden 404/401 errors and aligned the data model with the UI.
The Problem
Our web app (apps/web) started throwing two unrelated but critical issues that surfaced in the HAR logs of a production session on 28 Aug 2026:
AuthGuard navigation glitch – When a user’s JWT expired, AuthGuard called router.replace('/login'). In Next 13 (app router) router.replace is a client‑side navigation that sometimes fails silently when the component is already unmounted, leaving the UI in a half‑rendered state. The HAR showed a 401 response from the dashboard API, but the UI never redirected, so the user stayed on a broken page.






