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,
|
Group,
|
||||||
Text,
|
Text,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRef, useState, useEffect } from 'react';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
|
||||||
import { MicrophoneRecorder } from '@/components/MicrophoneRecorder';
|
import { MicrophoneRecorder } from '@/components/MicrophoneRecorder';
|
||||||
|
|
||||||
export default function ChatPage() {
|
export default function ChatPage() {
|
||||||
const router = useRouter();
|
|
||||||
const viewport = useRef<HTMLDivElement>(null);
|
const viewport = useRef<HTMLDivElement>(null);
|
||||||
const [input, setInput] = useState('');
|
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 (
|
* Root page - redirects to /chat if authenticated, /login if not
|
||||||
<Center h="100vh">
|
*/
|
||||||
<Paper w={400} p="xl">
|
export default async function Home() {
|
||||||
<Stack align="center">
|
const cookieStore = await cookies();
|
||||||
<Title order={1}>Ponderants</Title>
|
const authCookie = cookieStore.get('ponderants-auth');
|
||||||
<Button>Test Button</Button>
|
|
||||||
</Stack>
|
if (authCookie) {
|
||||||
</Paper>
|
redirect('/chat');
|
||||||
</Center>
|
} else {
|
||||||
);
|
redirect('/login');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user