'use client' import { useState } from 'react' import { createClient } from '@/lib/supabase/client' import { useRouter } from 'next/navigation' export default function LoginPage() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [isSignUp, setIsSignUp] = useState(false) const [loading, setLoading] = useState(false) const [error, setError] = useState('') const [message, setMessage] = useState('') const router = useRouter() const supabase = createClient() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError('') setMessage('') try { if (isSignUp) { const { error } = await supabase.auth.signUp({ email, password, options: { emailRedirectTo: `${window.location.origin}/onboarding`, }, }) if (error) throw error setMessage('Check your email to verify your account!') } else { const { error } = await supabase.auth.signInWithPassword({ email, password, }) if (error) throw error router.push('/') } } catch (err: any) { setError(err.message) } finally { setLoading(false) } } const handleGitHubLogin = async () => { const { error } = await supabase.auth.signInWithOAuth({ provider: 'github', options: { redirectTo: `${window.location.origin}/onboarding`, }, }) if (error) setError(error.message) } return (
{isSignUp ? 'Join AeThex Live' : 'Welcome back to AeThex Live'}
{error && ({isSignUp ? 'Already have an account?' : "Don't have an account?"}{' '}