mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 15:28:25 +00:00
Update Login.utils.tsx
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { NextRouter } from "next/router";
|
import { NextRouter, useRouter } from "next/router";
|
||||||
|
|
||||||
|
import { useServerConfig } from "@app/context";
|
||||||
|
import { useSelectOrganization } from "@app/hooks/api";
|
||||||
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
||||||
import { userKeys } from "@app/hooks/api/users/queries";
|
import { userKeys } from "@app/hooks/api/users/queries";
|
||||||
import { queryClient } from "@app/reactQuery";
|
import { queryClient } from "@app/reactQuery";
|
||||||
@@ -27,9 +29,21 @@ export const navigateUserToOrg = async (router: NextRouter, organizationId?: str
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const navigateUserToSelectOrg = (router: NextRouter, cliCallbackPort?: string) => {
|
export const useNavigateToSelectOrganization = () => {
|
||||||
queryClient.invalidateQueries(userKeys.getUser);
|
const { config } = useServerConfig();
|
||||||
|
const selectOrganization = useSelectOrganization();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const navigate = async (cliCallbackPort?: string) => {
|
||||||
|
if (config.defaultOrgId) {
|
||||||
|
await selectOrganization.mutateAsync({
|
||||||
|
organizationId: config.defaultOrgId
|
||||||
|
});
|
||||||
|
|
||||||
|
await navigateUserToOrg(router, config.defaultOrgId);
|
||||||
|
}
|
||||||
|
|
||||||
|
queryClient.invalidateQueries(userKeys.getUser);
|
||||||
let redirectTo = "/login/select-organization";
|
let redirectTo = "/login/select-organization";
|
||||||
|
|
||||||
if (cliCallbackPort) {
|
if (cliCallbackPort) {
|
||||||
@@ -37,4 +51,7 @@ export const navigateUserToSelectOrg = (router: NextRouter, cliCallbackPort?: st
|
|||||||
}
|
}
|
||||||
|
|
||||||
router.push(redirectTo, undefined, { shallow: true });
|
router.push(redirectTo, undefined, { shallow: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
return { navigateToSelectOrganization: navigate };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user