'use client'; import { useState, useEffect } 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 { Label } from '@/components/ui/label'; import { ArrowLeft, Loader2, CheckCircle, AlertCircle } from 'lucide-react'; import Link from 'next/link'; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'; export default function AccountSettingsPage() { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [fullName, setFullName] = useState(''); const [password, setPassword] = useState(''); const [message, setMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null); const router = useRouter(); const supabase = createClient(); useEffect(() => { const getUser = async () => { const { data: { user } } = await supabase.auth.getUser(); if (!user) { router.push('/login'); } else { setUser(user); setFullName(user.user_metadata?.full_name || ''); } setLoading(false); }; getUser(); }, [router, supabase]); const handleUpdateProfile = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); setMessage(null); try { const updates: any = { data: { full_name: fullName } }; if (password) { updates.password = password; } const { error } = await supabase.auth.updateUser(updates); if (error) { throw error; } setMessage({ type: 'success', text: 'Profile updated successfully' }); if (password) setPassword(''); // Clear password field on success } catch (error: any) { setMessage({ type: 'error', text: error.message }); } finally { setSaving(false); } }; if (loading) { return
Loading...
; } return (
Back to Profile Account Settings Update your personal information and security.
{/* Email (Read Only) */}
{/* Full Name */}
setFullName(e.target.value)} className="bg-[#141414] border-gray-700 text-white focus:border-red-600 focus:ring-red-600" placeholder="Enter your name" />
{/* Password */}
setPassword(e.target.value)} className="bg-[#141414] border-gray-700 text-white focus:border-red-600 focus:ring-red-600" placeholder="Leave blank to keep current password" />

Only enter a new password if you want to change it.

{/* Status Message */} {message && (
{message.type === 'success' ? : } {message.text}
)} {/* Submit Button */}
); }