diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 0f1d3f1c..a8bbd60d 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -31,7 +31,9 @@ export const AppRouter = memo( () => ( }> - } /> + }> + } /> + }> } /> } /> diff --git a/src/core/auth/RequireAuth.tsx b/src/core/auth/RequireAuth.tsx index 28d86e2a..f2e2b857 100644 --- a/src/core/auth/RequireAuth.tsx +++ b/src/core/auth/RequireAuth.tsx @@ -2,12 +2,18 @@ import { Outlet, useLocation } from 'react-router-dom' import { useAbsoluteNavigate } from 'src/shared/absolute-navigate' import { useUserProfile } from './useUserProfile' -export function RequireAuth() { +interface RequireAuthProps { + reverse?: boolean +} + +export function RequireAuth({ reverse }: RequireAuthProps) { const navigate = useAbsoluteNavigate() const location = useLocation() const user = useUserProfile() - if (!user.isAuthenticated && location.pathname !== '/auth/login') { + const isAuthenticated = !user.isAuthenticated && location.pathname !== '/auth/login' + + if (isAuthenticated && !reverse) { window.setTimeout(() => { navigate( { @@ -20,6 +26,11 @@ export function RequireAuth() { ) }) return null + } else if (reverse && !isAuthenticated) { + window.setTimeout(() => { + navigate(window.decodeURIComponent(location.search?.split('returnUrl=')[1]?.split('&')[0] ?? '/'), { replace: true }) + }) + return null } return