import { login, type AuthError } from '@/auth/authService'; import { registerPasskey, loginWithPasskey } from '@/auth/passkeyService'; import type { AuthUser } from '@/auth/types'; import { Button } from "@/components/ui/button"; import { DialogDescription } from '@radix-ui/react-dialog'; import React, { useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog'; import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs'; import { Home, LogIn, AlertCircle, Loader2, Fingerprint, Mail } from 'lucide-react'; interface LoginModalProps { isOpen: boolean; onPasskeyLogin: (user: AuthUser) => void; } const LoginModal: React.FC = ({ isOpen, onPasskeyLogin }) => { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [email, setEmail] = useState(''); if (!isOpen) return null; const handleSSOLogin = async () => { setIsLoading(true); setError(null); try { await login(); } catch (err) { setError((err as AuthError).message); setIsLoading(false); } }; const handlePasskeyLogin = async () => { setIsLoading(true); setError(null); try { const user = await loginWithPasskey(); onPasskeyLogin(user); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setIsLoading(false); } }; const handlePasskeyRegister = async () => { if (!email.trim()) { setError('Please enter your email address'); return; } setIsLoading(true); setError(null); try { const user = await registerPasskey(email.trim()); onPasskeyLogin(user); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setIsLoading(false); } }; const clearError = () => setError(null); return (
Wrongmove Your smart property search companion
{/* Error State */} {error && (

{error}

)} Sign In Sign Up
or
setEmail(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handlePasskeyRegister(); }} className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pl-10 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" />

A passkey uses your device's biometrics or security key for secure, passwordless authentication.

); }; export default LoginModal;