From a73b454a72a36934547562d2b56cfd2b497a3342 Mon Sep 17 00:00:00 2001 From: Albert Date: Sun, 9 Nov 2025 04:55:52 +0000 Subject: [PATCH] feat: Add authentication redirects for / and /chat routes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented server-side authentication redirects: - Root (/) redirects to /chat if authenticated, /login if not - /chat route requires authentication via layout component - Removed deprecated middleware file in favor of Next.js server components This ensures users are properly directed based on their authentication state. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/chat/layout.tsx | 21 +++++++++++++++++++++ app/chat/page.tsx | 4 +--- app/page.tsx | 26 ++++++++++++++------------ 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 app/chat/layout.tsx diff --git a/app/chat/layout.tsx b/app/chat/layout.tsx new file mode 100644 index 0000000..ee18e92 --- /dev/null +++ b/app/chat/layout.tsx @@ -0,0 +1,21 @@ +import { redirect } from 'next/navigation'; +import { cookies } from 'next/headers'; + +/** + * Chat route layout - ensures user is authenticated before showing chat + */ +export default async function ChatLayout({ + children, +}: { + children: React.ReactNode; +}) { + const cookieStore = await cookies(); + const authCookie = cookieStore.get('ponderants-auth'); + + // Redirect to login if not authenticated + if (!authCookie) { + redirect('/login'); + } + + return <>{children}; +} diff --git a/app/chat/page.tsx b/app/chat/page.tsx index d87580e..3315da4 100644 --- a/app/chat/page.tsx +++ b/app/chat/page.tsx @@ -12,12 +12,10 @@ import { Group, Text, } from '@mantine/core'; -import { useRouter } from 'next/navigation'; -import { useEffect, useRef, useState } from 'react'; +import { useRef, useState, useEffect } from 'react'; import { MicrophoneRecorder } from '@/components/MicrophoneRecorder'; export default function ChatPage() { - const router = useRouter(); const viewport = useRef(null); const [input, setInput] = useState(''); diff --git a/app/page.tsx b/app/page.tsx index e5b532d..3a31472 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,14 +1,16 @@ -import { Stack, Title, Paper, Button, Center } from '@mantine/core'; +import { redirect } from 'next/navigation'; +import { cookies } from 'next/headers'; -export default function Home() { - return ( -
- - - Ponderants - - - -
- ); +/** + * Root page - redirects to /chat if authenticated, /login if not + */ +export default async function Home() { + const cookieStore = await cookies(); + const authCookie = cookieStore.get('ponderants-auth'); + + if (authCookie) { + redirect('/chat'); + } else { + redirect('/login'); + } }