Urgent.News

What's breaking now, across thousands of outlets.

Tech

Fixing AuthGuard Navigation, 401 Handling, and Sales‑Pipeline FK in a Next.js + NestJS Monorepo

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…

TL;DR: Two critical issues surfaced in a Next.js + NestJS monorepo on 28 Aug 2026: AuthGuard navigation error when a JWT expired, and Sales-pipeline foreign-key mismatch causing cascade of “relation does not exist” errors. I fixed the problems by switching AuthGuard navigation to Next 13’s redirect() helper and adding explicit 401 handling on the dashboard page.

AuthGuard: I replaced the unreliable router.replace() to use redirect() from next/navigation. The server-side redirect guarantees a proper HTTP 302 before any client-side rendering. After successful login, the component checks for a valid token and clears stale tokens before rendering the protected children.

Sales-pipeline FK: The API referenced an incorrect table name (ventas_prop) instead of properties. I corrected this typo in the migration script, which now correctly maps the foreign key. Additionally, I added explicit 401 handling in the dashboard, removing stale tokens on authentication failure and redirecting the user to the login page. These changes eliminated hidden 404/401 errors, aligned the data model with the UI, and provided a seamless user experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Saturday 29 August →