Skip to content

Commit 18eb8a0

Browse files
committed
Fix login button not responding - attach listeners before Firebase init await, add 15s timeout to Firebase init
1 parent 61dd1ef commit 18eb8a0

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

index.html

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -972,14 +972,31 @@ <h4>Pending UPI payments <span id="pendingCount" class="pending-badge">0</span><
972972
let dashboardRefreshSeq=0, dashboardRefreshTimer=null, cacheRefreshTimer=null;
973973
// Configuration
974974

975+
// Attach login listeners early (before Firebase init await, so button always works)
976+
try {
977+
const loginBtn = $("loginBtn");
978+
if(loginBtn) loginBtn.addEventListener("click", login);
979+
} catch(e) { console.error("Failed to attach login button listener:", e); }
980+
try {
981+
const adminPass = $("adminPass");
982+
if(adminPass) adminPass.addEventListener("keydown", e=>{ if(e.key==="Enter") login(); });
983+
} catch(e) { console.error("Failed to attach password enter listener:", e); }
984+
try {
985+
const logoutBtn = $("logoutBtn");
986+
if(logoutBtn) logoutBtn.addEventListener("click", ()=>{ if(store) store.signOut(); });
987+
} catch(e) { console.error("Failed to attach logout button listener:", e); }
988+
975989
const notConfigured = Object.values(firebaseConfig).some(v => v === "PASTE_HERE");
976990
if(notConfigured){
977991
isLocalMode=true; store=makeLocalStore();
978992
showModeBanner("Test mode — running on this device with sample data. Add citizens, contributions and payments to try it out; everything is saved in this browser only. Paste your Firebase config into the file to go live.");
979993
} else {
980994
try{
981995
console.log("Initializing Firebase...");
982-
const fbModule = await loadFirebase(firebaseConfig);
996+
const fbModule = await Promise.race([
997+
loadFirebase(firebaseConfig),
998+
new Promise((_,reject) => setTimeout(()=>reject(new Error("timeout")), 15000))
999+
]);
9831000
console.log("Firebase loaded successfully");
9841001
store=makeFirebaseStore(fbModule);
9851002
console.log("Firebase store created");
@@ -1035,21 +1052,6 @@ <h4>Pending UPI payments <span id="pendingCount" class="pending-badge">0</span><
10351052
/* ============================================================
10361053
ADMIN AUTH
10371054
============================================================ */
1038-
// Attach listeners immediately at module load (before async Firebase initialization)
1039-
try {
1040-
const loginBtn = $("loginBtn");
1041-
if(loginBtn) loginBtn.addEventListener("click", login);
1042-
} catch(e) { console.error("Failed to attach login button listener:", e); }
1043-
1044-
try {
1045-
const adminPass = $("adminPass");
1046-
if(adminPass) adminPass.addEventListener("keydown", e=>{ if(e.key==="Enter") login(); });
1047-
} catch(e) { console.error("Failed to attach password enter listener:", e); }
1048-
1049-
try {
1050-
const logoutBtn = $("logoutBtn");
1051-
if(logoutBtn) logoutBtn.addEventListener("click", ()=>{ if(store) store.signOut(); });
1052-
} catch(e) { console.error("Failed to attach logout button listener:", e); }
10531055

10541056
async function login(){
10551057
if(!store){

0 commit comments

Comments
 (0)