fix: Add check for paths in useLastVisitedPath, closes #7655

This commit is contained in:
Tom Moor committed 2024-09-25 22:00:52 -04:00
1 parent 8a5e42071f
commit 1d4b05c9f6
2 files changed
+9 -7

No files matched your search

+6 -4
View File
@@ -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;
}
}
+3 -3
View File
@@ -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);