feat(auth): Implement LoginForm, RegisterForm and integrate with App
This commit is contained in:
@@ -1,10 +1,56 @@
|
||||
import { useState, useEffect } from "react"
|
||||
import { MainLayout } from "./components/layout/MainLayout"
|
||||
import { LoginForm } from "./components/auth/LoginForm"
|
||||
import { RegisterForm } from "./components/auth/RegisterForm"
|
||||
import { AuthService } from "./services/auth"
|
||||
|
||||
function App() {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false)
|
||||
const [authMode, setAuthMode] = useState<"login" | "register">("login")
|
||||
|
||||
useEffect(() => {
|
||||
setIsAuthenticated(AuthService.isAuthenticated())
|
||||
}, [])
|
||||
|
||||
const handleAuthSuccess = () => {
|
||||
setIsAuthenticated(true)
|
||||
}
|
||||
|
||||
const handleLogout = () => {
|
||||
AuthService.logout()
|
||||
setIsAuthenticated(false)
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-background p-4">
|
||||
{authMode === "login" ? (
|
||||
<LoginForm
|
||||
onSuccess={handleAuthSuccess}
|
||||
onToggleMode={() => setAuthMode("register")}
|
||||
/>
|
||||
) : (
|
||||
<RegisterForm
|
||||
onSuccess={handleAuthSuccess}
|
||||
onToggleMode={() => setAuthMode("login")}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1 className="text-2xl font-bold">Welcome to Election Analytics</h1>
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="text-2xl font-bold">Welcome to Election Analytics</h1>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="text-sm text-muted-foreground hover:text-primary underline"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-muted-foreground">
|
||||
Select a conversation from the sidebar or start a new one to begin your analysis.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user