'use client'; import { useState, useEffect, useRef } from 'react'; import { supabase } from '@/lib/supabase'; import { useRouter } from 'next/navigation'; import 'leaflet/dist/leaflet.css'; export default function Login() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [showPassword, setShowPassword] = useState(false); const router = useRouter(); const mapRef = useRef(null); const mapInstanceRef = useRef(null); useEffect(() => { let active = true; // Dynamically load Leaflet for the background map import('leaflet').then((L) => { if (!active) return; if (!mapInstanceRef.current && mapRef.current) { // Initialize map centered on Pontianak const map = L.map(mapRef.current, { center: [-0.0227, 109.3340], zoom: 13, zoomControl: false, dragging: false, scrollWheelZoom: false, doubleClickZoom: false, boxZoom: false, keyboard: false, attributionControl: false }); // Use CartoDB Positron for a clean, light background L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', { maxZoom: 19, subdomains: 'abcd' }).addTo(map); mapInstanceRef.current = map; // Force resize recalculation to ensure tiles render immediately setTimeout(() => { if (active && mapInstanceRef.current) { mapInstanceRef.current.invalidateSize(); } }, 150); } }); return () => { active = false; if (mapInstanceRef.current) { mapInstanceRef.current.remove(); mapInstanceRef.current = null; } }; }, []); const handleLogin = async (e) => { e.preventDefault(); setLoading(true); setError(null); const { data, error: authError } = await supabase.auth.signInWithPassword({ email, password, }); if (authError) { setError(authError.message); setLoading(false); return; } // Check if they need password rotation const { data: profile } = await supabase .from('profiles') .select('password_changed') .eq('id', data.user.id) .single(); if (profile && profile.password_changed === false) { router.push('/change-password'); } else { router.push('/'); } }; return (
{/* Return to Dashboard Button */} {/* Dynamic Leaflet Background */}
{/* Glassmorphism Dark/Blur Overlay */}
{/* Login Card */}

Sinergi Umat

Portal Manajemen Bantuan & Geotagging

{error && (
{error}
)}
setEmail(e.target.value)} style={{ width: '100%', padding: '12px 16px', borderRadius: '12px', border: '1px solid #cbd5e1', background: 'white', outline: 'none', transition: 'all 0.2s', color: '#1e293b', boxShadow: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.05)' }} onFocus={(e) => e.target.style.borderColor = 'var(--primary, #3b82f6)'} onBlur={(e) => e.target.style.borderColor = '#cbd5e1'} required />
setPassword(e.target.value)} style={{ width: '100%', padding: '12px 44px 12px 16px', borderRadius: '12px', border: '1px solid #cbd5e1', background: 'white', outline: 'none', transition: 'all 0.2s', color: '#1e293b', boxShadow: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.05)' }} onFocus={(e) => e.target.style.borderColor = 'var(--primary, #3b82f6)'} onBlur={(e) => e.target.style.borderColor = '#cbd5e1'} required />
); }