'use client' import { Mail, X } from 'lucide-react' import { useState } from 'react' import { authClient } from '../lib/auth/client' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/primitives/dialog' interface SignInDialogProps { open: boolean onOpenChange: (open: boolean) => void } /** * SignInDialog - Magic link authentication dialog */ export function SignInDialog({ open, onOpenChange }: SignInDialogProps) { const [email, setEmail] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) setIsLoading(true) try { // Use better-auth's magic link sign in const result = await authClient.signIn.magicLink({ email, callbackURL: window.location.origin, }) if (result.error) { setError(result.error.message || 'Failed to send magic link') } else { setSuccess(true) setEmail('') } } catch (err) { setError(err instanceof Error ? err.message : 'An unexpected error occurred') } finally { setIsLoading(false) } } const handleClose = () => { if (!isLoading) { onOpenChange(false) // Reset state after a short delay to avoid flash setTimeout(() => { setEmail('') setError(null) setSuccess(false) }, 200) } } return ( Sign in to Pascal {success ? (

Check your email

We've sent a magic link to {email}

Click the link in the email to sign in to your account.

) : (
setEmail(e.target.value)} />
{error && (
{error}
)}

We'll send you a magic link to sign in without a password.

)}
) }