Skip to content

Commit

Permalink
feat: dont redirect if heading towards root url
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed Jun 12, 2024
1 parent 7705297 commit 6fe2e23
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/AuthRedirects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { UserContext } from "../provider/UserContext";
export const RedirectIfNotLoggedIn = ({ children }: PropsWithChildren) => {
const { user } = useContext(UserContext);

const target = "/login" + `?redirect=${window.location.pathname}`;

let target = "/login";
if (window.location.pathname !== "/") {
target = target + `?redirect=${window.location.pathname}`;
}
return !user?.uid ? <Navigate to={target} replace /> : children;
};

Expand Down

0 comments on commit 6fe2e23

Please sign in to comment.