Inline the gate-redirect helper in the boundaries

resolveGateRedirect only supplied window.location.href to gateRedirectPath
from two call sites; drop the extra indirection and call gateRedirectPath
directly in the root and page error boundaries.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-16 19:41:51 +02:00
parent 3e2651cbe5
commit 94970bea6c
3 changed files with 6 additions and 34 deletions

View File

@@ -14,8 +14,9 @@
import { Navigate, useRouteError } from "react-router";
import { gateRedirectPath } from "#/lib/auth/continueUrl";
import { GlobalError } from "./GlobalError";
import { resolveGateRedirect } from "./resolveGateRedirect";
// Child-route boundary: a page failure is contained to the layout's Outlet, so
// the error renders inside the app chrome (TopBar + footer survive).
@@ -24,7 +25,7 @@ export function PageErrorBoundary() {
// Full-name / NDA gates are recoverable: send the user to the gate page and
// return them here afterwards, instead of showing an error.
const gateRedirect = resolveGateRedirect(error);
const gateRedirect = gateRedirectPath(error, window.location.href);
if (gateRedirect) {
return <Navigate replace to={gateRedirect} />;
}

View File

@@ -14,8 +14,9 @@
import { Navigate, useRouteError } from "react-router";
import { gateRedirectPath } from "#/lib/auth/continueUrl";
import { GlobalError } from "./GlobalError";
import { resolveGateRedirect } from "./resolveGateRedirect";
// Root route boundary: a failure in the layout (or anything above the page
// boundaries) takes down the whole tree, so it renders a standalone full-page
@@ -25,7 +26,7 @@ export function RootErrorBoundary() {
// Full-name / NDA gates are recoverable: send the user to the gate page and
// return them here afterwards, instead of showing an error.
const gateRedirect = resolveGateRedirect(error);
const gateRedirect = gateRedirectPath(error, window.location.href);
if (gateRedirect) {
return <Navigate replace to={gateRedirect} />;
}

View File

@@ -1,30 +0,0 @@
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import { gateRedirectPath } from "#/lib/auth/continueUrl";
// Maps a caught gate error to the route that resolves it, carrying the current
// URL as a `continue` target so the user returns here once the gate is cleared.
// Returns a router-relative path (basename applied by the router); the target
// page validates the continue URL via getSafeContinueUrl. Returns null for any
// other error so the boundary can fall through to its normal error UI.
export function resolveGateRedirect(error: unknown): string | null {
return gateRedirectPath(error, window.location.href);
}