'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 (
Portal Manajemen Bantuan & Geotagging
{error && (