'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { createClient } from '@/lib/supabase/client' import { Mail, Lock, User, Code2, Loader2 } from 'lucide-react' interface AuthFormProps { mode: 'login' | 'signup' } export function AuthForm({ mode }: AuthFormProps) { const router = useRouter() const supabase = createClient() const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [formData, setFormData] = useState({ email: '', password: '', fullName: '', }) const isSignup = mode === 'signup' const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError(null) try { if (isSignup) { const { error } = await supabase.auth.signUp({ email: formData.email, password: formData.password, options: { data: { full_name: formData.fullName, }, emailRedirectTo: `${process.env.NEXT_PUBLIC_APP_URL}/auth/callback`, }, }) if (error) throw error } else { const { error } = await supabase.auth.signInWithPassword({ email: formData.email, password: formData.password, }) if (error) throw error router.push('/dashboard') router.refresh() } } catch (err: any) { setError(err.message || 'An error occurred') } finally { setLoading(false) } } const handleOAuthLogin = async (provider: 'google' | 'github') => { try { const { error } = await supabase.auth.signInWithOAuth({ provider, options: { redirectTo: `${process.env.NEXT_PUBLIC_APP_URL}/auth/callback`, }, }) if (error) throw error } catch (err: any) { setError(err.message) } } return (
{error && (
{error}
)} {isSignup && (
setFormData({ ...formData, fullName: e.target.value })} className="w-full pl-10 pr-4 py-3 rounded-xl bg-dark-800 border border-dark-600 focus:border-primary-500 focus:outline-none transition-colors" required />
)}
setFormData({ ...formData, email: e.target.value })} className="w-full pl-10 pr-4 py-3 rounded-xl bg-dark-800 border border-dark-600 focus:border-primary-500 focus:outline-none transition-colors" required />
setFormData({ ...formData, password: e.target.value })} className="w-full pl-10 pr-4 py-3 rounded-xl bg-dark-800 border border-dark-600 focus:border-primary-500 focus:outline-none transition-colors" required minLength={6} />
Or continue with
{isSignup && (

By signing up, you agree to our{' '} Terms {' '}and{' '} Privacy Policy

)} {/* Dev Mode: Skip Auth */} {process.env.NODE_ENV === 'development' && ( <>
⚡ Dev Mode
)}
) }