From 4db761447d47c5322dbccdf8399b8c0d14de3427 Mon Sep 17 00:00:00 2001 From: Sarthak Srinivas Date: Tue, 4 Feb 2025 06:54:53 -0800 Subject: [PATCH 1/2] chore(logs): remove logs layout and page components to clean up unused code style(layout.tsx): comment out logs link in the layout to prevent navigation to removed logs page --- app/layout.tsx | 4 +-- app/logs/layout.tsx | 19 ----------- app/logs/page.tsx | 80 --------------------------------------------- 3 files changed, 2 insertions(+), 101 deletions(-) delete mode 100644 app/logs/layout.tsx delete mode 100644 app/logs/page.tsx diff --git a/app/layout.tsx b/app/layout.tsx index 464682c..c42161b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -65,12 +65,12 @@ export default async function RootLayout({ children }: PropsWithChildren) { > Chat - Logs - + */} )} diff --git a/app/logs/layout.tsx b/app/logs/layout.tsx deleted file mode 100644 index 096d846..0000000 --- a/app/logs/layout.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; -import { cookies } from 'next/headers'; -import { redirect } from 'next/navigation'; -import { PropsWithChildren } from 'react'; - -export default async function LogsLayout({ children }: PropsWithChildren) { - const cookieStore = cookies(); - const supabase = createServerComponentClient({ cookies: () => cookieStore }); - - const { - data: { user }, - } = await supabase.auth.getUser(); - - if (!user) { - return redirect('/login'); - } - - return <>{children}; -} \ No newline at end of file diff --git a/app/logs/page.tsx b/app/logs/page.tsx deleted file mode 100644 index 8a7c33e..0000000 --- a/app/logs/page.tsx +++ /dev/null @@ -1,80 +0,0 @@ -'use client'; - -import { useEffect, useState } from 'react'; -import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; -import { toast } from '@/components/ui/use-toast'; - -type Log = { - id: number; - created_at: string; - event_type: string; - details: string; - user_id: string; -}; - -export default function LogsPage() { - const [logs, setLogs] = useState([]); - const supabase = createClientComponentClient(); - - useEffect(() => { - const fetchLogs = async () => { - const { data, error } = await supabase - .from('logs') - .select('*') - .order('created_at', { ascending: false }); - - if (error) { - toast({ - variant: 'destructive', - description: 'Failed to fetch logs', - }); - return; - } - - setLogs(data || []); - }; - - fetchLogs(); - }, [supabase]); - - return ( -
-

System Logs

-
- - - - - - - - - - {logs.map((log) => ( - - - - - - ))} - -
- Timestamp - - Event Type - - Details -
- {new Date(log.created_at).toLocaleString()} - - {log.event_type} - - {log.details} -
- {logs.length === 0 && ( -
No logs found
- )} -
-
- ); -} \ No newline at end of file From fa218ccb51514d1865d2d8e6af4329caede10340 Mon Sep 17 00:00:00 2001 From: Sarthak Srinivas Date: Tue, 4 Feb 2025 07:20:28 -0800 Subject: [PATCH 2/2] feat(logs): create logs layout and page to display system logs with user authentication fix(layout.tsx): uncomment logs link in the root layout for navigation to logs page --- app/layout.tsx | 4 +-- logs/layout.tsx | 19 ++++++++++++ logs/page.tsx | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 logs/layout.tsx create mode 100644 logs/page.tsx diff --git a/app/layout.tsx b/app/layout.tsx index c42161b..464682c 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -65,12 +65,12 @@ export default async function RootLayout({ children }: PropsWithChildren) { > Chat - {/* Logs - */} + )} diff --git a/logs/layout.tsx b/logs/layout.tsx new file mode 100644 index 0000000..096d846 --- /dev/null +++ b/logs/layout.tsx @@ -0,0 +1,19 @@ +import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'; +import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; +import { PropsWithChildren } from 'react'; + +export default async function LogsLayout({ children }: PropsWithChildren) { + const cookieStore = cookies(); + const supabase = createServerComponentClient({ cookies: () => cookieStore }); + + const { + data: { user }, + } = await supabase.auth.getUser(); + + if (!user) { + return redirect('/login'); + } + + return <>{children}; +} \ No newline at end of file diff --git a/logs/page.tsx b/logs/page.tsx new file mode 100644 index 0000000..8a7c33e --- /dev/null +++ b/logs/page.tsx @@ -0,0 +1,80 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; +import { toast } from '@/components/ui/use-toast'; + +type Log = { + id: number; + created_at: string; + event_type: string; + details: string; + user_id: string; +}; + +export default function LogsPage() { + const [logs, setLogs] = useState([]); + const supabase = createClientComponentClient(); + + useEffect(() => { + const fetchLogs = async () => { + const { data, error } = await supabase + .from('logs') + .select('*') + .order('created_at', { ascending: false }); + + if (error) { + toast({ + variant: 'destructive', + description: 'Failed to fetch logs', + }); + return; + } + + setLogs(data || []); + }; + + fetchLogs(); + }, [supabase]); + + return ( +
+

System Logs

+
+ + + + + + + + + + {logs.map((log) => ( + + + + + + ))} + +
+ Timestamp + + Event Type + + Details +
+ {new Date(log.created_at).toLocaleString()} + + {log.event_type} + + {log.details} +
+ {logs.length === 0 && ( +
No logs found
+ )} +
+
+ ); +} \ No newline at end of file