[WEB-4943]fix: next path url redirection (#7817)
* fix: next path url redirection * fix: enhance URL redirection safety in authentication views Updated SignInAuthSpaceEndpoint, GitHubCallbackSpaceEndpoint, GitLabCallbackSpaceEndpoint, and GoogleCallbackSpaceEndpoint to include checks for allowed hosts and schemes before redirecting. This improves the security of URL redirection by ensuring only valid URLs are used. * chore: updated uitl to handle double / --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Nikhil <118773738+pablohashescobar@users.noreply.github.com>
This commit is contained in:
parent
3d06189723
commit
877c117c37
6 changed files with 99 additions and 26 deletions
|
|
@ -1,6 +1,9 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { useSearchParams, useRouter } from "next/navigation";
|
||||
// plane imports
|
||||
import { isValidNextPath } from "@plane/utils";
|
||||
// components
|
||||
import { UserLoggedIn } from "@/components/account/user-logged-in";
|
||||
import { LogoSpinner } from "@/components/common/logo-spinner";
|
||||
|
|
@ -10,6 +13,15 @@ import { useUser } from "@/hooks/store/use-user";
|
|||
|
||||
const HomePage = observer(() => {
|
||||
const { data: currentUser, isAuthenticated, isInitializing } = useUser();
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const nextPath = searchParams.get("next_path");
|
||||
|
||||
useEffect(() => {
|
||||
if (currentUser && isAuthenticated && nextPath && isValidNextPath(nextPath)) {
|
||||
router.replace(nextPath);
|
||||
}
|
||||
}, [currentUser, isAuthenticated, nextPath, router]);
|
||||
|
||||
if (isInitializing)
|
||||
return (
|
||||
|
|
@ -18,7 +30,16 @@ const HomePage = observer(() => {
|
|||
</div>
|
||||
);
|
||||
|
||||
if (currentUser && isAuthenticated) return <UserLoggedIn />;
|
||||
if (currentUser && isAuthenticated) {
|
||||
if (nextPath && isValidNextPath(nextPath)) {
|
||||
return (
|
||||
<div className="flex h-screen min-h-[500px] w-full justify-center items-center">
|
||||
<LogoSpinner />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return <UserLoggedIn />;
|
||||
}
|
||||
|
||||
return <AuthView />;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue