Do not set continue when not needed + infer organizationId to assume after pw sign in
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { AssumptionRequiredError, UnAuthenticatedError } from "@probo/relay";
|
import { AssumptionRequiredError, UnAuthenticatedError } from "@probo/relay";
|
||||||
import { Navigate, useRouteError } from "react-router";
|
import { Navigate, useLocation, useRouteError } from "react-router";
|
||||||
|
|
||||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||||
|
|
||||||
@@ -8,17 +8,18 @@ import { PageError } from "./PageError";
|
|||||||
export function OrganizationErrorBoundary() {
|
export function OrganizationErrorBoundary() {
|
||||||
const error = useRouteError();
|
const error = useRouteError();
|
||||||
const organizationId = useOrganizationId();
|
const organizationId = useOrganizationId();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const search = new URLSearchParams([
|
const search = new URLSearchParams();
|
||||||
["organization-id", organizationId],
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (window.location.href !== window.location.origin) {
|
if (location.pathname !== "/" || location.search !== "") {
|
||||||
search.set("continue", window.location.href);
|
search.set("continue", window.location.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const queryString = search.toString();
|
||||||
|
|
||||||
if (error instanceof UnAuthenticatedError) {
|
if (error instanceof UnAuthenticatedError) {
|
||||||
return <Navigate to={{ pathname: "/auth/login", search: "?" + search.toString() }} />;
|
return <Navigate to={{ pathname: "/auth/login", search: queryString ? "?" + queryString : "" }} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof AssumptionRequiredError) {
|
if (error instanceof AssumptionRequiredError) {
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
import { UnAuthenticatedError } from "@probo/relay";
|
import { UnAuthenticatedError } from "@probo/relay";
|
||||||
import { Navigate, useRouteError } from "react-router";
|
import { Navigate, useLocation, useRouteError } from "react-router";
|
||||||
|
|
||||||
import { PageError } from "./PageError";
|
import { PageError } from "./PageError";
|
||||||
|
|
||||||
export function RootErrorBoundary() {
|
export function RootErrorBoundary() {
|
||||||
const error = useRouteError();
|
const error = useRouteError();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const search = new URLSearchParams();
|
const search = new URLSearchParams();
|
||||||
if (window.location.href !== window.location.origin) {
|
|
||||||
|
if (location.pathname !== "/" || location.search !== "") {
|
||||||
search.set("continue", window.location.href);
|
search.set("continue", window.location.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const queryString = search.toString();
|
||||||
|
|
||||||
if (error instanceof UnAuthenticatedError) {
|
if (error instanceof UnAuthenticatedError) {
|
||||||
return (
|
return (
|
||||||
<Navigate to={{
|
<Navigate to={{
|
||||||
pathname: "/auth/login",
|
pathname: "/auth/login",
|
||||||
search: search.toString() ? "?" + search.toString() : "",
|
search: queryString ? "?" + queryString : "",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useTranslate } from "@probo/i18n";
|
|||||||
import { Button, Field, IconChevronLeft, useToast } from "@probo/ui";
|
import { Button, Field, IconChevronLeft, useToast } from "@probo/ui";
|
||||||
import type { FormEventHandler } from "react";
|
import type { FormEventHandler } from "react";
|
||||||
import { useMutation } from "react-relay";
|
import { useMutation } from "react-relay";
|
||||||
import { Link, useLocation, useSearchParams } from "react-router";
|
import { Link, matchPath, useLocation, useSearchParams } from "react-router";
|
||||||
import { graphql } from "relay-runtime";
|
import { graphql } from "relay-runtime";
|
||||||
|
|
||||||
import type { PasswordSignInPageMutation } from "#/__generated__/iam/PasswordSignInPageMutation.graphql";
|
import type { PasswordSignInPageMutation } from "#/__generated__/iam/PasswordSignInPageMutation.graphql";
|
||||||
@@ -37,7 +37,7 @@ export default function PasswordSignInPage() {
|
|||||||
if (!emailValue || !passwordValue) return;
|
if (!emailValue || !passwordValue) return;
|
||||||
|
|
||||||
const continueUrlParam = searchParams.get("continue");
|
const continueUrlParam = searchParams.get("continue");
|
||||||
let safeContinueUrl: string;
|
let safeContinueUrl: URL;
|
||||||
if (continueUrlParam) {
|
if (continueUrlParam) {
|
||||||
let continueUrl: URL;
|
let continueUrl: URL;
|
||||||
try {
|
try {
|
||||||
@@ -45,18 +45,23 @@ export default function PasswordSignInPage() {
|
|||||||
} catch {
|
} catch {
|
||||||
continueUrl = new URL(window.location.origin);
|
continueUrl = new URL(window.location.origin);
|
||||||
}
|
}
|
||||||
safeContinueUrl = window.location.origin + continueUrl.pathname + continueUrl.search;
|
safeContinueUrl = new URL(continueUrl.pathname + continueUrl.search, window.location.origin);
|
||||||
} else {
|
} else {
|
||||||
safeContinueUrl = window.location.origin;
|
safeContinueUrl = new URL(window.location.origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const match = matchPath(
|
||||||
|
{ path: "/organizations/:organizationId", caseSensitive: false, end: false },
|
||||||
|
safeContinueUrl.pathname,
|
||||||
|
);
|
||||||
|
|
||||||
signIn({
|
signIn({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
email: emailValue,
|
email: emailValue,
|
||||||
password: passwordValue,
|
password: passwordValue,
|
||||||
// Assume when signing in
|
// Assume when signing in
|
||||||
organizationId: searchParams.get("organization-id"),
|
organizationId: match && match.params.organizationId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onCompleted: (_, error) => {
|
onCompleted: (_, error) => {
|
||||||
@@ -73,7 +78,7 @@ export default function PasswordSignInPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location.href = safeContinueUrl;
|
window.location.href = safeContinueUrl.href;
|
||||||
},
|
},
|
||||||
onError: (e) => {
|
onError: (e) => {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
Reference in New Issue
Block a user