From 3ab598db4084ca038b16cdaff573b61af9b0e19b Mon Sep 17 00:00:00 2001 From: Yogesh Chaudhary Date: Mon, 17 Aug 2026 07:46:47 +0530 Subject: [PATCH 1/2] fix RequireAuth: default returnTo to current URL when not provided --- src/client/components.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/components.tsx b/src/client/components.tsx index 3d7e605..b8b9206 100644 --- a/src/client/components.tsx +++ b/src/client/components.tsx @@ -28,7 +28,9 @@ export function RequireAuth({ children, returnTo }: RequireAuthProps) { useEffect(() => { if (!isLoading && !isAuthenticated) { - loginWithRedirect({ returnTo }); + loginWithRedirect({ + returnTo: returnTo ?? window.location.pathname + window.location.search + }); } }, [isAuthenticated, isLoading, loginWithRedirect, returnTo]); From 55243f36e18d5fdf5830920b50b2c7c7dc886b51 Mon Sep 17 00:00:00 2001 From: Yogesh Chaudhary Date: Mon, 17 Aug 2026 08:08:40 +0530 Subject: [PATCH 2/2] test: add missing test for RequireAuth default returnTo --- __tests__/client/components.test.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/__tests__/client/components.test.tsx b/__tests__/client/components.test.tsx index 4cbd85a..0a92c0b 100644 --- a/__tests__/client/components.test.tsx +++ b/__tests__/client/components.test.tsx @@ -100,6 +100,25 @@ describe('RequireAuth', () => { ); expect(loginWithRedirect).toHaveBeenCalledWith({ returnTo: '/dashboard' }); }); + + it('defaults returnTo to current pathname and search when not provided', () => { + const loginWithRedirect = vi.fn(); + const ctx = createMockAuth0Context({ + session: null, + isAuthenticated: false, + loginWithRedirect + }); + render( + + + x + + + ); + expect(loginWithRedirect).toHaveBeenCalledWith({ + returnTo: window.location.pathname + window.location.search + }); + }); }); // ─── RequireRole ──────────────────────────────────────────────────────────────