Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

577 B
Raw Blame
import { useMemo } from "react";
import { useRouterState } from "@tanstack/react-router";

import { ProjectType } from "@app/hooks/api/projects/types";

export const useGetProjectTypeFromRoute = () => {
  const { location } = useRouterState();

  return useMemo(() => {
    const segments = location.pathname.split("/");
    const type = segments?.[2];
    if (!type) return ProjectType.SecretManager;

    // second element would be /projects/$projectId/<type>
    return Object.values(ProjectType).find((el) => el === type) || ProjectType.SecretManager;
  }, [location]);
};