Rename redirect-path to continue + handle redirection on forbidden from wrong org assume
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<8717e91a7e1602c06f6c67fa76580ecf>>
|
||||
* @generated SignedSource<<d0c32c536987c19da427a6088151bd09>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -11,8 +11,8 @@
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type ReauthenticationReason = "POLICY_REQUIREMENT" | "SENSITIVE_ACTION" | "SESSION_EXPIRED";
|
||||
export type AssumeOrganizationSessionInput = {
|
||||
continue: string;
|
||||
organizationId: string;
|
||||
redirectPath: string;
|
||||
};
|
||||
export type AssumePageMutation$variables = {
|
||||
input: AssumeOrganizationSessionInput;
|
||||
|
||||
@@ -11,9 +11,12 @@ export function OrganizationErrorBoundary() {
|
||||
|
||||
const search = new URLSearchParams([
|
||||
["organization-id", organizationId],
|
||||
["redirect-path", window.location.pathname + window.location.search],
|
||||
]);
|
||||
|
||||
if (window.location.href !== window.location.origin) {
|
||||
search.set("continue", window.location.href);
|
||||
}
|
||||
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
return <Navigate to={{ pathname: "/auth/login", search: "?" + search.toString() }} />;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,19 @@ import { PageError } from "./PageError";
|
||||
export function RootErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
|
||||
const search = new URLSearchParams([
|
||||
["redirect-path", window.location.pathname + window.location.search],
|
||||
]);
|
||||
const search = new URLSearchParams();
|
||||
if (window.location.href !== window.location.origin) {
|
||||
search.set("continue", window.location.href);
|
||||
}
|
||||
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
return <Navigate to={{ pathname: "/auth/login", search: "?" + search.toString() }} />;
|
||||
return (
|
||||
<Navigate to={{
|
||||
pathname: "/auth/login",
|
||||
search: search.toString() ? "?" + search.toString() : "",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <PageError error={error instanceof Error ? error : new Error("unknown error")} />;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useTranslate } from "@probo/i18n";
|
||||
import { Button, Field, IconChevronLeft, useToast } from "@probo/ui";
|
||||
import type { FormEventHandler } from "react";
|
||||
import { useMutation } from "react-relay";
|
||||
import { Link, useLocation, useNavigate, useSearchParams } from "react-router";
|
||||
import { Link, useLocation, useSearchParams } from "react-router";
|
||||
import { graphql } from "relay-runtime";
|
||||
|
||||
import type { PasswordSignInPageMutation } from "#/__generated__/iam/PasswordSignInPageMutation.graphql";
|
||||
@@ -21,7 +21,6 @@ const signInMutation = graphql`
|
||||
export default function PasswordSignInPage() {
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { __ } = useTranslate();
|
||||
const { toast } = useToast();
|
||||
@@ -56,10 +55,11 @@ export default function PasswordSignInPage() {
|
||||
),
|
||||
variant: "error",
|
||||
});
|
||||
window.location.href = "/";
|
||||
return;
|
||||
}
|
||||
|
||||
void navigate(searchParams.get("redirect-path") ?? "/");
|
||||
window.location.href = searchParams.get("continue") ?? window.location.origin;
|
||||
},
|
||||
onError: (e) => {
|
||||
toast({
|
||||
@@ -67,6 +67,7 @@ export default function PasswordSignInPage() {
|
||||
description: e.message,
|
||||
variant: "error",
|
||||
});
|
||||
window.location.href = "/";
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -130,7 +130,7 @@ function NavigateToSSOLoginURL(props: {
|
||||
}
|
||||
|
||||
const url = new URL(ssoLoginURL.value);
|
||||
url.search = "?" + searchParams.toString();
|
||||
url.search = searchParams.toString();
|
||||
|
||||
window.location.href = url.toString();
|
||||
}, [__, navigate, ssoLoginURL, toast, searchParams]);
|
||||
|
||||
@@ -38,18 +38,18 @@ function AssumePageInner() {
|
||||
|
||||
const [assumeOrganizationSession] = useMutation<AssumePageMutation>(assumeMutation);
|
||||
|
||||
const redirectPath = searchParams.get("redirect-path") ?? `/organizations/${organizationId}`;
|
||||
const continueUrl = searchParams.get("continue") ?? new URL(`/organizations/${organizationId}`, window.location.origin).toString();
|
||||
|
||||
useEffect(() => {
|
||||
assumeOrganizationSession({
|
||||
variables: {
|
||||
input: { organizationId, redirectPath },
|
||||
input: { organizationId, continue: continueUrl },
|
||||
},
|
||||
onError: (error) => {
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
const search = new URLSearchParams([
|
||||
["organization-id", organizationId],
|
||||
["redirect-path", redirectPath],
|
||||
["continue", continueUrl],
|
||||
]);
|
||||
|
||||
void navigate({ pathname: "/auth/login", search: "?" + search.toString() });
|
||||
@@ -68,7 +68,7 @@ function AssumePageInner() {
|
||||
switch (result.__typename) {
|
||||
case "PasswordRequired":
|
||||
search.set("organization-id", organizationId);
|
||||
search.set("redirect-path", redirectPath);
|
||||
search.set("continue", continueUrl);
|
||||
|
||||
void navigate({ pathname: "/auth/password-login", search: "?" + search.toString() });
|
||||
break;
|
||||
@@ -79,11 +79,11 @@ function AssumePageInner() {
|
||||
window.location.href = samlSSOLoginURL.toString();
|
||||
break;
|
||||
default:
|
||||
void navigate(redirectPath);
|
||||
window.location.href = continueUrl;
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [organizationId, navigate, assumeOrganizationSession, redirectPath, searchParams]);
|
||||
}, [organizationId, navigate, assumeOrganizationSession, continueUrl, searchParams]);
|
||||
|
||||
return (
|
||||
<AuthLayout>
|
||||
|
||||
Reference in New Issue
Block a user