'use client' import { useState, useEffect, Suspense } from 'react' import { useSearchParams, useRouter } from 'next/navigation' import { LoginForm } from '@/components/auth/LoginForm' import { RegisterForm } from '@/components/auth/RegisterForm' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { useAuth } from '@/contexts/AuthContext' import { Header } from '@/components/header' import { Footer } from '@/components/footer' import Link from 'next/link' import { BookOpen, Search, Settings, User, Edit, Tag } from 'lucide-react' // Main auth component with search params handling function AuthPageContent() { const searchParams = useSearchParams() const router = useRouter() const [mode, setMode] = useState<'login' | 'register'>('login') const [shouldRedirect, setShouldRedirect] = useState(false) useEffect(() => { const modeParam = searchParams.get('mode') if (modeParam === 'register') { setMode('register') } // Only redirect if there's a returnUrl (user was redirected here) or if they just logged in const returnUrl = searchParams.get('returnUrl') if (returnUrl) { setShouldRedirect(true) } }, [searchParams]) const { user, logout, loading } = useAuth() // Only redirect if shouldRedirect is true (not just because user exists) useEffect(() => { if (!loading && user && shouldRedirect) { const returnUrl = searchParams.get('returnUrl') if (returnUrl) { router.push(decodeURIComponent(returnUrl)) } else { router.push('/dashboard') } } }, [user, loading, router, searchParams, shouldRedirect]) if (loading) { return (

Loading...

) } if (user) { return (
{/* Welcome Section */} Welcome back, {user.name}! You're logged in and ready to start creating amazing content {/* Quick Actions */}
Topic Management Create and manage your topics Account Settings Manage your account and preferences
{/* User Info */} Account Information
Email: {user.email}
Role: {user.role}
Provider: {user.provider}
Verified: {user.isVerified ? 'Yes' : 'No'}
) } return (

Authentication Demo

Test the authentication system with login and registration

{mode === 'login' ? ( setMode('register')} /> ) : ( setMode('login')} /> )}
) } // Wrapper component with Suspense boundary export default function AuthPage() { return (
} >
) }