-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
25 lines (22 loc) · 1.03 KB
/
utils.js
File metadata and controls
25 lines (22 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
import { getFirestore, doc, getDoc } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
import { firebaseConfig } from "../firebase-config.js";
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
/**
* Checks if the current user is an admin by fetching their admin document.
*/
export async function checkAdminStatus(uid) {
try {
const adminDocRef = doc(db, 'admins', uid);
const adminSnap = await getDoc(adminDocRef);
if (adminSnap.exists()) {
const data = adminSnap.data();
return data.role === 'admin' || data.role === 'superadmin';
}
return false;
} catch (e) {
console.error("Error checking admin status:", e);
return false;
}
}