'use client' import { createClient } from '@/lib/supabase/client' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useState } from 'react' import { Mail, Lock, Loader2, ArrowLeft, Key } from 'lucide-react' import { isPasskeySupported, authenticateWithPasskey } from '@/lib/passkeys' export default function LoginPage() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState(null) const [isLoading, setIsLoading] = useState(false) const [isGoogleLoading, setIsGoogleLoading] = useState(false) const [isPasskeyLoading, setIsPasskeyLoading] = useState(false) const [passkeySupported] = useState(() => isPasskeySupported()) const router = useRouter() const handleLogin = async (e: React.FormEvent) => { e.preventDefault() const supabase = createClient() setIsLoading(true) setError(null) try { const { error } = await supabase.auth.signInWithPassword({ email, password, }) if (error) throw error router.push('/dashboard') } catch (error: unknown) { setError(error instanceof Error ? error.message : 'An error occurred') } finally { setIsLoading(false) } } const handleGoogleLogin = async () => { const supabase = createClient() setIsGoogleLoading(true) setError(null) try { const { error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: `${window.location.origin}/auth/callback`, }, }) if (error) throw error } catch (error: unknown) { setError(error instanceof Error ? error.message : 'An error occurred') setIsGoogleLoading(false) } } const handlePasskeyLogin = async () => { const supabase = createClient() setIsPasskeyLoading(true) setError(null) try { const credential = await authenticateWithPasskey() if (!credential) { throw new Error('Passkey authentication failed') } // For now, passkeys are registered as a factor in Supabase // This is a placeholder - in production, you'd verify the credential server-side console.log('[v0] Passkey authentication initiated:', credential.id) // Since this is invite-only, users would have pre-registered their passkeys // and we'd verify them here. For now, show success. setError('Passkey authentication requires server-side verification setup') } catch (error: unknown) { const message = error instanceof Error ? error.message : 'Passkey authentication failed' setError(message) } finally { setIsPasskeyLoading(false) } } return (
{/* Background elements */}
{/* Back to home */} Back to home {/* Card */}
{/* Header */}
Cloudrite

Welcome back

Sign in to your account to continue

{/* Passkey Button */} {passkeySupported && ( )} {/* Google OAuth Button */} {/* Divider */}
Or continue with email
{/* Email/Password Form */}
setEmail(e.target.value)} className="pl-10 h-12" />
setPassword(e.target.value)} className="pl-10 h-12" />
{error && (

{error}

)}
{/* Footer */}

Need an account?{' '} Contact us {' '}to request access.

) }