diff --git a/app/hooks/useLastVisitedPath.tsx b/app/hooks/useLastVisitedPath.tsx index b4776d80ba..41197e179e 100644 --- a/app/hooks/useLastVisitedPath.tsx +++ b/app/hooks/useLastVisitedPath.tsx @@ -3,7 +3,7 @@ import { getCookie, removeCookie, setCookie } from "tiny-cookie"; import usePersistedState from "~/hooks/usePersistedState"; import Logger from "~/utils/Logger"; import history from "~/utils/history"; -import { isValidPostLoginRedirect } from "~/utils/urls"; +import { isAllowedLoginRedirect } from "~/utils/urls"; /** * Hook to set locally and return the document or collection that the user last visited. This is @@ -20,7 +20,9 @@ export function useLastVisitedPath(): [string, (path: string) => void] { const setPathAsLastVisitedPath = React.useCallback( (path: string) => { - path !== lastVisitedPath && setLastVisitedPath(path); + if (isAllowedLoginRedirect(path) && path !== lastVisitedPath) { + setLastVisitedPath(path); + } }, [lastVisitedPath, setLastVisitedPath] ); @@ -36,7 +38,7 @@ export function useLastVisitedPath(): [string, (path: string) => void] { export function setPostLoginPath(path: string) { const key = "postLoginRedirectPath"; - if (isValidPostLoginRedirect(path)) { + if (isAllowedLoginRedirect(path)) { setCookie(key, path, { expires: 1 }); try { @@ -74,7 +76,7 @@ export function usePostLoginPath() { cleanup?.(); }); - if (isValidPostLoginRedirect(path)) { + if (isAllowedLoginRedirect(path)) { return path; } } diff --git a/app/utils/urls.ts b/app/utils/urls.ts index e1ce391f2b..c2eba8337b 100644 --- a/app/utils/urls.ts +++ b/app/utils/urls.ts @@ -47,10 +47,10 @@ export function redirectTo(url: string) { } /** - * Check if the path is a valid redirect after login + * Check if the path is a valid path for redirect after login. * * @param path * @returns boolean indicating if the path is a valid redirect */ -export const isValidPostLoginRedirect = (path: string) => - !["/", "/create", "/home", "/logout"].includes(path); +export const isAllowedLoginRedirect = (path: string) => + !["/", "/create", "/home", "/logout", "/auth/"].includes(path);