Implement redirect-path for password method
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { AssumptionRequiredError, UnAuthenticatedError } from "@probo/relay";
|
||||
import { Navigate, useLocation, useRouteError } from "react-router";
|
||||
import { Navigate, useRouteError } from "react-router";
|
||||
|
||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||
|
||||
@@ -7,15 +7,26 @@ import { PageError } from "./PageError";
|
||||
|
||||
export function OrganizationErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
const location = useLocation();
|
||||
const organizationId = useOrganizationId();
|
||||
|
||||
const search = new URLSearchParams([
|
||||
["organization-id", organizationId],
|
||||
["redirect-path", window.location.href],
|
||||
]);
|
||||
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
return <Navigate to="/auth/login" state={{ from: location.pathname }} />;
|
||||
return <Navigate to={{ pathname: "/auth/login", search: "?" + search.toString() }} />;
|
||||
}
|
||||
|
||||
if (error instanceof AssumptionRequiredError) {
|
||||
return <Navigate to={`/organizations/${organizationId}/assume`} state={{ from: location.pathname }} />;
|
||||
return (
|
||||
<Navigate
|
||||
to={{
|
||||
pathname: `/organizations/${organizationId}/assume`,
|
||||
search: "?" + search.toString(),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <PageError error={error instanceof Error ? error : new Error("unknown error")} />;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { UnAuthenticatedError } from "@probo/relay";
|
||||
import { Navigate, useLocation, useRouteError } from "react-router";
|
||||
import { Navigate, useRouteError } from "react-router";
|
||||
|
||||
import { PageError } from "./PageError";
|
||||
|
||||
export function RootErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
const location = useLocation();
|
||||
|
||||
const search = new URLSearchParams([["redirect-path", window.location.href]]);
|
||||
|
||||
if (error instanceof UnAuthenticatedError) {
|
||||
return <Navigate to="/auth/login" state={{ from: location.pathname }} />;
|
||||
return <Navigate to={{ pathname: "/auth/login", search: "?" + search.toString() }} />;
|
||||
}
|
||||
|
||||
return <PageError error={error instanceof Error ? error : new Error("unknown error")} />;
|
||||
|
||||
Reference in New Issue
Block a user