Skip to content

Commit 935c40a

Browse files
committed
Attempting to fix Firebase connection
1 parent 761a682 commit 935c40a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ jobs:
1515
- name: Generate Firebase Config File
1616
run: |
1717
echo "Generating firebase-config.js..."
18-
cat <<EOF > firebase-config.js
18+
cat <<EOF > scripts/firebase-config.js
19+
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.3.1/firebase-app.js";
20+
import { getAuth } from "https://www.gstatic.com/firebasejs/11.3.1/firebase-auth.js";
21+
import { getFirestore } from "https://www.gstatic.com/firebasejs/11.3.1/firebase-firestore.js";
22+
1923
const firebaseConfig = {
2024
apiKey: "${{ secrets.FIREBASE_API_KEY }}",
2125
authDomain: "${{ secrets.FIREBASE_AUTH_DOMAIN }}",
@@ -24,7 +28,12 @@ jobs:
2428
messagingSenderId: "${{ secrets.FIREBASE_MESSAGING_SENDER_ID }}",
2529
appId: "${{ secrets.FIREBASE_APP_ID }}"
2630
};
27-
window.firebaseConfig = firebaseConfig;
31+
32+
const app = initializeApp(firebaseConfig);
33+
const auth = getAuth(app);
34+
const db = getFirestore(app);
35+
36+
export { auth, db };
2837
EOF
2938
3039
- name: Install Dependencies

scripts/auth.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { doc, getDoc, setDoc, updateDoc } from "https://www.gstatic.com/firebase
99

1010
// Wait for DOM to load
1111
document.addEventListener("DOMContentLoaded", () => {
12+
console.log("DOM fully loaded and parsed");
1213
onAuthStateChanged(auth, handleAuthStateChanged);
1314

1415
// Set up event listeners
@@ -46,11 +47,13 @@ async function handleLogin(e) {
4647
try {
4748
const userCredential = await signInWithEmailAndPassword(auth, email, password);
4849
const user = userCredential.user;
50+
console.log("User logged in:", user);
4951

5052
// Get user status using the modular syntax
5153
const userDoc = await getDoc(doc(db, "users", user.uid));
5254
if (userDoc.exists()) {
5355
const userData = userDoc.data();
56+
console.log("User data:", userData);
5457
if (userData.status !== "approved") {
5558
await signOut(auth);
5659
if (errorMsg) {
@@ -89,6 +92,7 @@ async function handleRegister(e) {
8992
try {
9093
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
9194
const user = userCredential.user;
95+
console.log("User registered:", user);
9296

9397
// Store user status in Firestore as "pending"
9498
await setDoc(doc(db, "users", user.uid), {
@@ -123,6 +127,7 @@ function handleLogout(e) {
123127

124128
signOut(auth)
125129
.then(() => {
130+
console.log("User logged out");
126131
window.location.href = "index.html";
127132
})
128133
.catch((error) => {
@@ -186,6 +191,7 @@ async function handleApproveUser(e) {
186191
await updateDoc(doc(db, "users", userId), {
187192
status: "approved",
188193
});
194+
console.log("User approved:", userId);
189195

190196
// Show success message
191197
const message = document.getElementById("message");

scripts/firebase-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ const app = initializeApp(firebaseConfig);
1818
const auth = getAuth(app);
1919
const db = getFirestore(app);
2020

21+
console.log("Firebase initialized with the following config:", firebaseConfig);
22+
2123
// Export the initialized instances so other scripts can use them
2224
export { auth, db };

0 commit comments

Comments
 (0)