Do not call useAssume on every route change

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-02-10 17:28:19 +04:00
parent 070000c46a
commit 260f196f9c
3 changed files with 5 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ import type { useAssumeMutation } from "#/__generated__/iam/useAssumeMutation.gr
import { useOrganizationId } from "../useOrganizationId";
interface UseAssumeParameters {
afterAssumePath: string;
afterAssumePath?: string;
onSuccess: () => void;
}
@@ -58,7 +58,7 @@ export function useAssume(params: UseAssumeParameters) {
if (error instanceof UnAuthenticatedError) {
const search = new URLSearchParams([
["organization-id", organizationId],
["redirect-path", afterAssumePath],
["redirect-path", afterAssumePath ?? window.location.href],
]);
void navigate({ pathname: "/auth/login", search: "?" + search.toString() });
@@ -76,7 +76,7 @@ export function useAssume(params: UseAssumeParameters) {
switch (result.__typename) {
case "PasswordRequired":
search.set("organization-id", organizationId);
search.set("redirect-path", afterAssumePath);
search.set("redirect-path", afterAssumePath ?? window.location.href);
void navigate({ pathname: "/auth/passord-login", search: "?" + search.toString() });
break;

View File

@@ -1,7 +1,6 @@
import { Skeleton } from "@probo/ui";
import { Suspense, useCallback } from "react";
import { useQueryLoader } from "react-relay";
import { useLocation } from "react-router";
import type { ViewerMembershipLayoutQuery } from "#/__generated__/iam/ViewerMembershipLayoutQuery.graphql";
import { useAssume } from "#/hooks/iam/useAssume";
@@ -15,7 +14,6 @@ import {
function ViewerMembershipLayoutQueryLoader() {
const organizationId = useOrganizationId();
const location = useLocation();
const [queryRef, loadQuery] = useQueryLoader<ViewerMembershipLayoutQuery>(
viewerMembershipLayoutQuery,
@@ -30,10 +28,7 @@ function ViewerMembershipLayoutQueryLoader() {
[loadQuery, organizationId],
);
useAssume({
afterAssumePath: location.pathname,
onSuccess: onAssumeSuccess,
});
useAssume({ onSuccess: onAssumeSuccess });
if (!queryRef) {
return <Skeleton className="w-full h-screen" />;

View File

@@ -1,7 +1,6 @@
import { Skeleton } from "@probo/ui";
import { Suspense, useCallback } from "react";
import { useQueryLoader } from "react-relay";
import { useLocation } from "react-router";
import type { ViewerMembershipLayoutQuery } from "#/__generated__/iam/ViewerMembershipLayoutQuery.graphql";
import { useAssume } from "#/hooks/iam/useAssume";
@@ -18,7 +17,6 @@ function EmployeeLayoutQueryLoader() {
const [queryRef, loadQuery] = useQueryLoader<ViewerMembershipLayoutQuery>(
viewerMembershipLayoutQuery,
);
const location = useLocation();
const onAssumeSuccess = useCallback(
() =>
@@ -29,10 +27,7 @@ function EmployeeLayoutQueryLoader() {
[loadQuery, organizationId],
);
useAssume({
afterAssumePath: location.pathname,
onSuccess: onAssumeSuccess,
});
useAssume({ onSuccess: onAssumeSuccess });
if (!queryRef) {
return <Skeleton className="w-full h-screen" />;