diff --git a/src/router.tsx b/src/router.tsx index 83dbde5..ebfcde2 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -5,7 +5,7 @@ import { Authentication } from "./views/Authentication"; import { RedirectIfNotLoggedIn, RedirectIfSignedIn, -} from "./utils/RedirectIfNotLoggedIn"; +} from "./utils/AuthRedirects"; import { Goals } from "./views/Goals"; import { NewLayout } from "./views/NewLayout"; import { routes } from "./routes"; diff --git a/src/utils/RedirectIfNotLoggedIn.tsx b/src/utils/AuthRedirects.tsx similarity index 55% rename from src/utils/RedirectIfNotLoggedIn.tsx rename to src/utils/AuthRedirects.tsx index 7b46a55..8efb298 100644 --- a/src/utils/RedirectIfNotLoggedIn.tsx +++ b/src/utils/AuthRedirects.tsx @@ -5,11 +5,17 @@ import { UserContext } from "../provider/UserContext"; export const RedirectIfNotLoggedIn = ({ children }: PropsWithChildren) => { const { user } = useContext(UserContext); - return !user?.uid ? : children; + const target = "/login" + `?redirect=${window.location.pathname}`; + + return !user?.uid ? : children; }; export const RedirectIfSignedIn = ({ children }: PropsWithChildren) => { const { user } = useContext(UserContext); - return user?.uid ? : children; + const query = new URLSearchParams(window.location.search); + + const target = query.get("redirect") || "/dashboard"; + + return user?.uid ? : children; };