'use client'; import { useRef, useState } from 'react'; import { useRouter } from 'next/navigation'; import { createClient } from '@/lib/supabase/client'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { X } from 'lucide-react'; import Link from 'next/link'; import HCaptcha from '@hcaptcha/react-hcaptcha'; export default function LoginPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [captchaToken, setCaptchaToken] = useState(null); const captchaRef = useRef(null); const router = useRouter(); const supabase = createClient(); const handleGoogleLogin = async () => { setLoading(true); const { error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: `${location.origin}/auth/callback`, }, }); if (error) { setError(error.message); setLoading(false); } }; const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); if (!captchaToken) { setError('Please complete the captcha'); return; } setLoading(true); setError(''); const { error } = await supabase.auth.signInWithPassword({ email, password, options: { captchaToken, }, }); if (error) { setError(error.message); setLoading(false); setCaptchaToken(null); captchaRef.current?.resetCaptcha(); } else { router.push('/profile'); router.refresh(); } }; return (
Start streaming now with Cineprime
setEmail(e.target.value)} className="bg-black/40 border-gray-600 text-white placeholder:text-gray-500 h-12" required />
setPassword(e.target.value)} className="bg-black/40 border-gray-600 text-white h-12" required />
{error && (
{error}
)}
setCaptchaToken(token)} onExpire={() => setCaptchaToken(null)} ref={captchaRef} theme="dark" />
Don't have an account? Sign Up
); }