Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat: cleaner store

dextmorgne692411d69c3
diff --git a/middleware.ts b/middleware.ts
new file mode 100644
index 00000000..06069133
--- /dev/null
+++ b/middleware.ts
@@ -0,0 +1,18 @@
+import { updateSession } from '@/lib/supabase/middleware'
+import { NextRequest } from 'next/server'
+
+export async function middleware(request: NextRequest) {
+ return await updateSession(request)
+}
+export const config = {
+ matcher: [
+ /*
+ * Match all request paths except for the ones starting with:
+ * - _next/static (static files)
+ * - _next/image (image optimization files)
+ * - favicon.ico (favicon file)
+ * Feel free to modify this pattern to include more paths.
+ */
+ '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
+ ],
+}
\ No newline at end of file
diff --git a/src/app/api/investigations/[investigation_id]/socials/route.ts b/src/app/api/investigations/[investigation_id]/socials/route.ts
new file mode 100644
index 00000000..7c18b80d
--- /dev/null
+++ b/src/app/api/investigations/[investigation_id]/socials/route.ts
@@ -0,0 +1,29 @@
+import { createClient } from "@/lib/supabase/server"
+import { NextResponse } from "next/server"
+
+export async function GET(_: Request, { params }: { params: Promise<{ investigation_id: string }> }) {
+ const { investigation_id } = await params
+ try {
+ const supabase = await createClient()
+ const {
+ data: { user },
+ error: userError,
+ } = await supabase.auth.getUser();
+ if (!user || userError) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
+ }
+ const { data: socials, error } = await supabase
+ .from('social_accounts')
+ .select(`
+ *
+ `)
+ .eq("investigation_id", investigation_id)
+
+ if (error) {
+ return NextResponse.json({ error: error.message }, { status: 500 })
+ }
+ return NextResponse.json({ socials })
+ } catch (error) {
+ return NextResponse.json({ error: "Internal Server Error" }, { status: 500 })
+ }
+}
\ No newline at end of file
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index 1219ac77..92859b59 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -27,7 +27,7 @@ const DashboardPage = async () => {
<Button variant='secondary'><FolderIcon className='h-4 w-4' />Create organization</Button> */}
</div>
</div>
- <div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-5'>{investigations.map((investigation) => (
+ <div className='grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-5'>{investigations.map((investigation) => (
<Investigation key={investigation.id} investigation={investigation} />
))}
</div>
diff --git a/src/app/investigations/[investigation_id]/left.tsx b/src/app/investigations/[investigation_id]/left.tsx
index 87936144..9a3d969b 100644
--- a/src/app/investigations/[investigation_id]/left.tsx
+++ b/src/app/investigations/[investigation_id]/left.tsx
@@ -1,23 +1,49 @@
"use client"
import { Skeleton } from "@/components/ui/skeleton"
import { cn } from "@/lib/utils"
-import { AtSignIcon, PhoneIcon, UserIcon } from "lucide-react"
+import { AtSignIcon, PhoneIcon, RotateCwIcon, UserIcon } from "lucide-react"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { useInvestigationStore } from "@/store/investigation-store"
import { usePlatformIcons } from "@/lib/hooks/use-platform-icons"
import { useFlowStore } from "@/store/flow-store"
+import { Input } from "@/components/ui/input"
+import { Button } from "@/components/ui/button"
+import { useState, useMemo } from "react"
const Left = ({ investigation_id }: { investigation_id: string }) => {
const platformsIcons = usePlatformIcons()
const { currentNode, setCurrentNode } = useFlowStore()
+ const [filterValue, setFilterValue] = useState("")
// Utiliser le hook useInvestigationData pour récupérer les données
const {
individuals,
emails,
phones,
- socials
+ socials,
+ refetchAll
} = useInvestigationStore((state) => state.useInvestigationData(investigation_id))
+ const { isRefetching } = useInvestigationStore()
+
+ // Filtrer les données
+ const filteredData = useMemo(() => {
+ const searchTerm = filterValue.toLowerCase().trim()
+ return {
+ individuals: individuals.data.filter(individual =>
+ individual.full_name.toLowerCase().includes(searchTerm)
+ ),
+ emails: emails.data.filter(email =>
+ email.email.toLowerCase().includes(searchTerm)
+ ),
+ phones: phones.data.filter(phone =>
+ phone.phone_number.toLowerCase().includes(searchTerm)
+ ),
+ socials: socials.data.filter(social =>
+ (social.username?.toLowerCase() || social.profile_url?.toLowerCase() || "")
+ .includes(searchTerm)
+ )
+ }
+ }, [filterValue, individuals.data, emails.data, phones.data, socials.data])
// Composant réutilisable pour le skeleton loader
const LoadingSkeleton = () => (
@@ -30,17 +56,33 @@ const Left = ({ investigation_id }: { investigation_id: string }) => {
return (
<div className="flex flex-col w-full">
+ <div className="flex items-center gap-2 p-2 border-b">
+ <Input
+ className="h-7"
+ placeholder="Filter..."
+ value={filterValue}
+ onChange={(e) => setFilterValue(e.target.value)}
+ />
+ <Button
+ className="h-7 w-7 opacity-70"
+ variant="ghost"
+ disabled={isRefetching}
+ onClick={refetchAll}
+ >
+ <RotateCwIcon className={cn(isRefetching && 'animate-spin', 'h-5 w-5')} />
+ </Button>
+ </div>
<Accordion type="single" collapsible defaultValue="individuals">
<AccordionItem value="individuals">
<AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
- Profiles {!individuals.isLoading && <>({individuals.data.length})</>}
+ Profiles {!individuals.isLoading && <>({filteredData.individuals.length})</>}
</AccordionTrigger>
<AccordionContent>
{individuals.isLoading ? (
<LoadingSkeleton />
) : (
<ul>
- {individuals.data.map((individual) => (
+ {filteredData.individuals.map((individual) => (
<li
className={cn(
"hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
@@ -66,14 +108,14 @@ const Left = ({ investigation_id }: { investigation_id: string }) => {
<Accordion type="single" collapsible defaultValue="emails">
<AccordionItem value="emails">
<AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
- Emails {!emails.isLoading && <>({emails.data.length})</>}
+ Emails {!emails.isLoading && <>({filteredData.emails.length})</>}
</AccordionTrigger>
<AccordionContent>
{emails.isLoading ? (
<LoadingSkeleton />
) : (
<ul>
- {emails.data.map((email) => (
+ {filteredData.emails.map((email) => (
<li
className={cn(
"hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
@@ -92,17 +134,18 @@ const Left = ({ investigation_id }: { investigation_id: string }) => {
</AccordionContent>
</AccordionItem>
</Accordion>
+
<Accordion type="single" collapsible defaultValue="phones">
<AccordionItem value="phones">
<AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
- Phones {!phones.isLoading && <>({phones.data.length})</>}
+ Phones {!phones.isLoading && <>({filteredData.phones.length})</>}
</AccordionTrigger>
<AccordionContent>
{phones.isLoading ? (
<LoadingSkeleton />
) : (
<ul>
- {phones.data.map((phone) => (
+ {filteredData.phones.map((phone) => (
<li
className={cn(
"hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
@@ -125,14 +168,14 @@ const Left = ({ investigation_id }: { investigation_id: string }) => {
<Accordion type="single" collapsible defaultValue="socials">
<AccordionItem value="socials">
<AccordionTrigger className="p-2 px-4 hover:bg-sidebar-accent text-sidebar-accent-foreground/60 hover:text-sidebar-accent-foreground text-sm rounded-none">
- Socials {!socials.isLoading && <>({socials.data.length})</>}
+ Socials {!socials.isLoading && <>({filteredData.socials.length})</>}
</AccordionTrigger>
<AccordionContent>
{socials.isLoading ? (
<LoadingSkeleton />
) : (
<ul>
- {socials.data.map((social) => (
+ {filteredData.socials.map((social) => (
<li
className={cn(
"hover:bg-sidebar-accent text-sidebar-accent-foreground/90 hover:text-sidebar-accent-foreground text-sm",
diff --git a/src/components/investigations/graph.tsx b/src/components/investigations/graph.tsx
index 0db342ed..af8f866a 100644
--- a/src/components/investigations/graph.tsx
+++ b/src/components/investigations/graph.tsx
@@ -44,7 +44,7 @@ const nodeTypes = {
address: AddressNode
};
-const LayoutFlow = ({ refetch, theme }: { refetch: any, theme: ColorMode }) => {
+const LayoutFlow = ({ refetch, isLoading, theme }: { refetch: any, isLoading: boolean, theme: ColorMode }) => {
const { fitView, zoomIn, zoomOut, addNodes, getNode, setCenter } = useReactFlow();
const { investigation_id } = useParams();
const { settings } = useInvestigationStore();
@@ -60,7 +60,6 @@ const LayoutFlow = ({ refetch, theme }: { refetch: any, theme: ColorMode }) => {
onPaneClick,
currentNode,
resetNodeStyles,
- reloading
} = useFlowStore();
useEffect(() => {
@@ -133,8 +132,8 @@ const LayoutFlow = ({ refetch, theme }: { refetch: any, theme: ColorMode }) => {
<Panel position="top-right" className='flex items-center gap-1'>
<div className='flex flex-col items-end gap-2'>
<div className='flex gap-1 items-center'>
- <Button size="icon" disabled={reloading} variant="outline" onClick={refetch}>
- <RotateCwIcon className={cn('h-4 w-4', reloading && 'animate-spin')} />
+ <Button size="icon" disabled={isLoading} variant="outline" onClick={refetch}>
+ <RotateCwIcon className={cn('h-4 w-4', isLoading && 'animate-spin')} />
</Button>
<NewActions addNodes={addNodes} />
</div>
@@ -211,10 +210,9 @@ export default function Graph({ graphQuery }: { graphQuery: any }) {
</div>
);
}
-
return (
<ReactFlowProvider>
- <LayoutFlow refetch={refetch} theme={resolvedTheme as ColorMode} />
+ <LayoutFlow refetch={refetch} isLoading={isLoading} theme={resolvedTheme as ColorMode} />
</ReactFlowProvider>
);
}
\ No newline at end of file
diff --git a/src/components/investigations/layout.tsx b/src/components/investigations/layout.tsx
index 3ced6d16..0f3bd040 100644
--- a/src/components/investigations/layout.tsx
+++ b/src/components/investigations/layout.tsx
@@ -5,7 +5,7 @@ import CaseSelector from './case-selector';
import NewCase from '@/components/dashboard/new-case';
import SearchModal from '@/components/dashboard/search-palette';
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
-import { PanelRightIcon, PlusIcon } from 'lucide-react';
+import { PanelRightIcon, PlusIcon, RotateCwIcon } from 'lucide-react';
import Logo from '@/components/logo';
import { useInvestigationStore } from '@/store/investigation-store';
import { Button } from '../ui/button';
@@ -13,6 +13,7 @@ import { ScrollArea } from '../ui/scroll-area';
import Assistant from '../assistant';
import { AppSidebar } from '../app-sidebar';
import { SidebarProvider } from '../ui/sidebar';
+import { cn } from '@/lib/utils';
const InvestigationLayout = ({
children,
@@ -25,7 +26,8 @@ const InvestigationLayout = ({
investigation_id: string
user: any
}) => {
- const { panelOpen, setPanelOpen } = useInvestigationStore()
+ const { panelOpen, setPanelOpen, useInvestigationData, isRefetching } = useInvestigationStore()
+ const { refetchAll } = useInvestigationData(investigation_id)
return (
<SidebarProvider defaultOpen={false}>
<AppSidebar user={user} defaultChecked={false} />
diff --git a/src/components/investigations/new-actions.tsx b/src/components/investigations/new-actions.tsx
index b1e915e0..c9c3f31d 100644
--- a/src/components/investigations/new-actions.tsx
+++ b/src/components/investigations/new-actions.tsx
@@ -40,9 +40,8 @@ export default function NewActions({ addNodes }: { addNodes: any }) {
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
- <Button variant="outline" className="gap-2">
+ <Button variant="outline" size={"icon"} className="gap-2">
<Plus className="h-4 w-4" />
- Individual
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
diff --git a/src/lib/supabase/middleware.ts b/src/lib/supabase/middleware.ts
index 304b266a..208c07f9 100644
--- a/src/lib/supabase/middleware.ts
+++ b/src/lib/supabase/middleware.ts
@@ -5,7 +5,6 @@ export async function updateSession(request: NextRequest) {
let supabaseResponse = NextResponse.next({
request,
})
-
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
diff --git a/src/middleware.ts b/src/middleware.ts
index 06069133..f17527fa 100644
--- a/src/middleware.ts
+++ b/src/middleware.ts
@@ -4,6 +4,7 @@ import { NextRequest } from 'next/server'
export async function middleware(request: NextRequest) {
return await updateSession(request)
}
+
export const config = {
matcher: [
/*
diff --git a/src/store/investigation-store.ts b/src/store/investigation-store.ts
index 9edacfea..51b9e835 100644
--- a/src/store/investigation-store.ts
+++ b/src/store/investigation-store.ts
@@ -2,7 +2,7 @@
import { create } from "zustand"
import { persist, createJSONStorage } from "zustand/middleware"
-import { useQuery, useQueryClient, type QueryObserverResult } from "@tanstack/react-query"
+import { useQuery, type QueryObserverResult } from "@tanstack/react-query"
import type { Investigation, Individual, Email, Phone, Social, IP, Relation, Address } from "@/types/investigation"
// Define a generic type for query results
@@ -38,6 +38,7 @@ interface InvestigationState {
currentNode: any
panelOpen: boolean
investigation: Investigation | null
+ isRefetching: boolean
// UI Actions
setFilters: (filters: any) => void
@@ -54,15 +55,16 @@ interface InvestigationState {
setHandleDeleteInvestigation: (handler: () => Promise<void>) => void
// Query Hooks
- useInvestigationData: (investigationId: string) => InvestigationData
- refetchAll: (investigationId: string) => Promise<void>
+ useInvestigationData: (investigationId: string) => InvestigationData & {
+ refetchAll: () => Promise<void>
+ }
}
const isServer = typeof window === "undefined"
export const useInvestigationStore = create(
persist<InvestigationState>(
- (set, _) => ({
+ (set, get) => ({
// UI State
filters: {},
settings: {
@@ -76,6 +78,7 @@ export const useInvestigationStore = create(
currentNode: null,
panelOpen: false,
investigation: null,
+ isRefetching: false,
// UI Actions
setFilters: (filters) => set({ filters }),
@@ -92,6 +95,7 @@ export const useInvestigationStore = create(
const wrapRefetch = async (refetch: () => Promise<QueryObserverResult>) => {
await refetch()
}
+
const investigationQuery = useQuery<Investigation>({
queryKey: ["investigation", investigationId, 'investigation'],
queryFn: async () => {
@@ -101,6 +105,7 @@ export const useInvestigationStore = create(
return data.investigation as Investigation
},
})
+
const individualsQuery = useQuery<Individual[]>({
queryKey: ["investigation", investigationId, "individuals"],
queryFn: async () => {
@@ -110,6 +115,7 @@ export const useInvestigationStore = create(
return data.individuals
},
})
+
const emailsQuery = useQuery<Email[]>({
queryKey: ["investigation", investigationId, "emails"],
queryFn: async () => {
@@ -119,6 +125,7 @@ export const useInvestigationStore = create(
return data.emails
},
})
+
const phonesQuery = useQuery<Phone[]>({
queryKey: ["investigation", investigationId, "phones"],
queryFn: async () => {
@@ -128,6 +135,31 @@ export const useInvestigationStore = create(
return data.phones
},
})
+
+ const socialsQuery = useQuery<Social[]>({
+ queryKey: ["investigation", investigationId, "socials"],
+ queryFn: async () => {
+ const res = await fetch(`/api/investigations/${investigationId}/socials`)
+ if (!res.ok) throw new Error("Failed to fetch socials")
+ const data = await res.json()
+ return data.socials
+ },
+ })
+
+ const refetchAll = async () => {
+ set({ isRefetching: true })
+ try {
+ await Promise.all([
+ individualsQuery.refetch(),
+ emailsQuery.refetch(),
+ phonesQuery.refetch(),
+ socialsQuery.refetch(),
+ ])
+ } finally {
+ set({ isRefetching: false })
+ }
+ }
+
return {
investigation: {
data: investigationQuery.data as Investigation,
@@ -150,9 +182,9 @@ export const useInvestigationStore = create(
refetch: () => wrapRefetch(phonesQuery.refetch),
},
socials: {
- data: [],
- isLoading: false,
- refetch: async () => { },
+ data: socialsQuery.data ?? [],
+ isLoading: socialsQuery.isLoading,
+ refetch: () => wrapRefetch(socialsQuery.refetch),
},
ips: {
data: [],
@@ -169,22 +201,9 @@ export const useInvestigationStore = create(
isLoading: false,
refetch: async () => { },
},
+ refetchAll,
}
},
- refetchAll: async (investigationId: string) => {
- const queryClient = useQueryClient()
- await Promise.all([
- queryClient.invalidateQueries({
- queryKey: ["investigation", investigationId, "individuals"]
- }),
- queryClient.invalidateQueries({
- queryKey: ["investigation", investigationId, "emails"]
- }),
- queryClient.invalidateQueries({
- queryKey: ["investigation", investigationId, "phones"]
- }),
- ])
- },
}),
{
name: "investigation-storage",
@@ -194,5 +213,4 @@ export const useInvestigationStore = create(
}),
},
)
-)
-
+)
\ No newline at end of file
diff --git a/styles/globals.css b/styles/globals.css
index ea5482b4..b59c8b41 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -25,7 +25,7 @@
--accent-foreground: hsl(0 0% 9%);
--destructive: hsl(0 84.2% 60.2%);
--destructive-foreground: hsl(0 0% 98%);
- --border: hsl(0 0% 89.8%);
+ --border: hsla(0, 0%, 90%, 0.807);
--input: hsl(0 0% 89.8%);
--ring: hsl(0 0% 3.9%);
--chart-1: hsl(12 76% 61%);
@@ -63,7 +63,7 @@
--accent-foreground: hsl(0 0% 98%);
--destructive: hsl(0 62.8% 30.6%);
--destructive-foreground: hsl(0 0% 98%);
- --border: hsl(0, 0%, 23%);
+ --border: hsla(0, 0%, 23%, 0.67);
--input: hsl(0 0% 14.9%);
--ring: hsl(0 0% 83.1%);
--chart-1: hsl(220 70% 50%);