feat: Add authentication redirects for / and /chat routes
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 <noreply@anthropic.com>
This commit is contained in:
21
app/chat/layout.tsx
Normal file
21
app/chat/layout.tsx
Normal file
@@ -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}</>;
|
||||
}
|
||||
@@ -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<HTMLDivElement>(null);
|
||||
const [input, setInput] = useState('');
|
||||
|
||||
|
||||
26
app/page.tsx
26
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 (
|
||||
<Center h="100vh">
|
||||
<Paper w={400} p="xl">
|
||||
<Stack align="center">
|
||||
<Title order={1}>Ponderants</Title>
|
||||
<Button>Test Button</Button>
|
||||
</Stack>
|
||||
</Paper>
|
||||
</Center>
|
||||
);
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user