Skip to content

Commit 3427e3c

Browse files
committed
Fix: Add batches collection to Firestore rules and add debug logging
1 parent ffd6842 commit 3427e3c

3 files changed

Lines changed: 87 additions & 2 deletions

File tree

β€Žfirestore.rulesβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ service cloud.firestore {
77
return request.auth != null;
88
}
99

10-
// Departments, Semesters, Subjects: Public Read/Write for Dev
10+
// Departments, Batches, Semesters, Subjects: Public Read/Write for Dev
1111
match /departments/{dept} {
1212
allow read, write: if true;
1313
}
14+
15+
match /batches/{batch} {
16+
allow read, write: if true;
17+
}
18+
1419
match /semesters/{sem} {
1520
allow read, write: if true;
1621
}
22+
1723
match /subjects/{sub} {
1824
allow read, write: if true;
1925
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use client";
2+
3+
import { useEffect, useState } from "react";
4+
import { getDepartments } from "@/lib/firebase/firestore";
5+
6+
export default function FirebaseTest() {
7+
const [status, setStatus] = useState("Testing...");
8+
const [departments, setDepartments] = useState<any[]>([]);
9+
const [error, setError] = useState<string | null>(null);
10+
11+
useEffect(() => {
12+
testFirebase();
13+
}, []);
14+
15+
async function testFirebase() {
16+
try {
17+
console.log("πŸ”₯ Testing Firebase connection...");
18+
const data = await getDepartments();
19+
console.log("βœ… Firebase connected! Departments:", data);
20+
setDepartments(data);
21+
setStatus(data.length > 0 ? "βœ… Connected - Data found!" : "⚠️ Connected - No data");
22+
} catch (err: any) {
23+
console.error("❌ Firebase error:", err);
24+
setError(err.message);
25+
setStatus("❌ Connection failed");
26+
}
27+
}
28+
29+
return (
30+
<div style={{ padding: "2rem", maxWidth: "600px", margin: "0 auto" }}>
31+
<h1>Firebase Connection Test</h1>
32+
<div style={{
33+
padding: "1rem",
34+
background: status.includes("βœ…") ? "#d1fae5" : status.includes("⚠️") ? "#fef3c7" : "#fee2e2",
35+
borderRadius: "8px",
36+
marginBottom: "1rem"
37+
}}>
38+
<strong>Status:</strong> {status}
39+
</div>
40+
41+
{error && (
42+
<div style={{ padding: "1rem", background: "#fee2e2", borderRadius: "8px", marginBottom: "1rem" }}>
43+
<strong>Error:</strong> {error}
44+
</div>
45+
)}
46+
47+
<div>
48+
<strong>Departments ({departments.length}):</strong>
49+
{departments.length > 0 ? (
50+
<ul>
51+
{departments.map(d => (
52+
<li key={d.id}>{d.name} (ID: {d.id})</li>
53+
))}
54+
</ul>
55+
) : (
56+
<p>No departments found. Please create some in the management page.</p>
57+
)}
58+
</div>
59+
60+
<div style={{ marginTop: "2rem", padding: "1rem", background: "#f3f4f6", borderRadius: "8px" }}>
61+
<h3>Next Steps:</h3>
62+
<ol>
63+
<li>If status is "Connected - No data": Go to <a href="/dashboard/manage">/dashboard/manage</a> to create departments</li>
64+
<li>If status is "Connection failed": Check Firebase configuration in .env.local</li>
65+
<li>Check browser console for detailed logs</li>
66+
</ol>
67+
</div>
68+
</div>
69+
);
70+
}

β€Žsrc/components/public/NotesBrowser.tsxβ€Ž

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,32 @@ export default function NotesBrowser() {
2626
}, []);
2727

2828
async function loadDepartments() {
29+
console.log('πŸ” Loading departments...');
2930
const data = await getDepartments();
31+
console.log('πŸ“Š Departments loaded:', data);
3032
setDepartments(data);
3133
if (data.length > 0) {
34+
console.log('βœ… Auto-selecting first department:', data[0]);
3235
handleDeptClick(data[0]);
36+
} else {
37+
console.warn('⚠️ No departments found in database');
3338
}
3439
}
3540

3641
async function handleDeptClick(dept: any) {
3742
if (selectedDept?.id === dept.id && !isSearching) return;
3843

44+
console.log('🏒 Department selected:', dept);
3945
setSelectedDept(dept);
4046
setSelectedBatch(null);
4147
setSelectedSem(null);
4248
setSelectedSub(null);
4349
setSearchQuery("");
4450
setIsSearching(false);
45-
setBatches(await getBatches(dept.id));
51+
console.log('πŸ” Loading batches for department:', dept.id);
52+
const batchData = await getBatches(dept.id);
53+
console.log('πŸ“Š Batches loaded:', batchData);
54+
setBatches(batchData);
4655
}
4756

4857
async function handleBatchClick(batch: any) {

0 commit comments

Comments
Β (0)