appscms-tools-theme 5.0.9 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,81 +2,155 @@ const profileButton = document.getElementById("profileButton");
2
2
  const userModal = document.getElementById("userModal");
3
3
  let isModalOpen = false;
4
4
 
5
- profileButton.addEventListener("click", () => {
6
- if (isModalOpen) {
7
- userModal.style.display = "none";
8
- isModalOpen = false;
9
- } else {
10
- userModal.style.display = "block";
11
- isModalOpen = true;
12
- }
13
- });
14
-
15
- // Close modal when clicking outside
16
- document.addEventListener("click", (event) => {
17
- if (
18
- !profileButton.contains(event.target) &&
19
- !userModal.contains(event.target)
20
- ) {
21
- userModal.style.display = "none";
22
- isModalOpen = false;
23
- }
24
- });
5
+ if (profileButton && userModal) {
6
+ profileButton.addEventListener("click", () => {
7
+ if (isModalOpen) {
8
+ userModal.style.display = "none";
9
+ isModalOpen = false;
10
+ } else {
11
+ userModal.style.display = "block";
12
+ isModalOpen = true;
13
+ }
14
+ });
15
+
16
+ // Close modal when clicking outside
17
+ document.addEventListener("click", (event) => {
18
+ if (
19
+ profileButton &&
20
+ userModal &&
21
+ !profileButton.contains(event.target) &&
22
+ !userModal.contains(event.target)
23
+ ) {
24
+ userModal.style.display = "none";
25
+ isModalOpen = false;
26
+ }
27
+ });
28
+ }
29
+
25
30
  // Get the modal elements
26
- const modal = document.getElementById("sideModal");
27
- const modalOverlay = document.getElementById("modalOverlay");
31
+ const sideModal = document.getElementById("sideModal");
32
+ const modalOverlayy = document.getElementById("modalOverlay");
28
33
  const openModalBtn = document.querySelector(".open-modal-btn");
29
34
  const closeModalBtn = document.querySelector(".close-modal-btn");
30
35
 
31
36
  // Function to open the modal
32
37
  function openModal() {
33
- modalOverlay.style.display = "block";
34
- // Slight delay for the overlay to appear before the modal slides in
35
- setTimeout(() => {
36
- modal.style.right = "0";
37
- }, 50);
38
+ if (modalOverlayy && sideModal) {
39
+ modalOverlayy.style.display = "block";
40
+ // Slight delay for the overlay to appear before the modal slides in
41
+ setTimeout(() => {
42
+ sideModal.style.right = "0";
43
+ }, 50);
44
+ }
38
45
  }
39
46
 
40
47
  // Function to close the modal
41
48
  function closeModal() {
42
- modal.style.right = "-90%";
43
- // Wait for the animation to complete before hiding the overlay
44
- setTimeout(() => {
45
- modalOverlay.style.display = "none";
46
- }, 300);
49
+ if (sideModal && modalOverlayy) {
50
+ sideModal.style.right = "-90%";
51
+ // Wait for the animation to complete before hiding the overlay
52
+ setTimeout(() => {
53
+ modalOverlayy.style.display = "none";
54
+ }, 300);
55
+ }
47
56
  }
48
57
 
49
58
  // Event listeners
50
- openModalBtn.addEventListener("click", openModal);
51
- closeModalBtn.addEventListener("click", closeModal);
52
- modalOverlay.addEventListener("click", closeModal);
59
+ if (openModalBtn) {
60
+ openModalBtn.addEventListener("click", openModal);
61
+ }
62
+
63
+ if (closeModalBtn) {
64
+ closeModalBtn.addEventListener("click", closeModal);
65
+ }
66
+
67
+ if (modalOverlayy) {
68
+ modalOverlayy.addEventListener("click", closeModal);
69
+ }
53
70
 
54
71
  // Prevent closing when clicking inside the modal
55
- modal.addEventListener("click", function (event) {
56
- event.stopPropagation();
57
- });
58
- if (window.location.pathname === "/profile") {
72
+ if (sideModal) {
73
+ sideModal.addEventListener("click", function (event) {
74
+ event.stopPropagation();
75
+ });
76
+ }
77
+
78
+ if (
79
+ window.location.pathname === "/profile" &&
80
+ document.querySelector(".login-button")
81
+ ) {
59
82
  document.querySelector(".login-button").addEventListener("click", openModal);
60
83
  }
61
84
 
62
- // Firebase configuration - Replace with your own Firebase config
85
+ // Firebase configuration
86
+ let firebaseConfig;
87
+
88
+ async function loadFirebaseConfig() {
89
+ try {
90
+ // Try to get config from Netlify function
91
+ const hostname = window.location.hostname;
92
+ const port = window.location.port;
93
+
94
+ let baseUrl = "";
95
+
96
+ // Development environment detection
97
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
98
+ // When running locally, we need to specify which port the Netlify Functions are running on
99
+ // Default Netlify CLI functions port is 8888, but could be 9000 or custom
100
+ baseUrl = "http://localhost:9000"; // Adjust this if your Netlify Functions are on a different port
101
+ }
102
+
103
+ // Make the request to the Netlify function with credentials included
104
+
105
+ const response = await fetch(
106
+ `http://localhost:9000/.netlify/functions/get-firebase-config`
107
+ );
108
+
109
+ if (response.ok) {
110
+ firebaseConfig = await response.json();
111
+
112
+ // Check if we got all required config fields
113
+ if (
114
+ firebaseConfig.apiKey &&
115
+ firebaseConfig.authDomain &&
116
+ firebaseConfig.projectId
117
+ ) {
118
+ // Initialize Firebase with the config
119
+ if (typeof firebase !== "undefined") {
120
+ initializeFirebase();
121
+ } else {
122
+ console.error("Firebase SDK not loaded");
123
+ }
124
+ } else {
125
+ console.error("Incomplete Firebase configuration received");
126
+ }
127
+ } else {
128
+ console.error("Failed to load Firebase config:", response.status);
129
+ }
130
+ } catch (error) {
131
+ console.log(error);
132
+ console.error("Error loading Firebase config:", error);
133
+ }
134
+ }
135
+
136
+ function initializeFirebase() {
137
+ if (!firebase.apps.length) {
138
+ firebase.initializeApp(firebaseConfig);
63
139
 
64
- // Initialize Firebase
65
- firebase.initializeApp(firebaseConfig);
66
- const auth = firebase.auth();
140
+ setupAuthListeners();
141
+ }
142
+ }
143
+
144
+ function setupAuthListeners() {
145
+ const auth = firebase.auth();
67
146
 
68
- // Check for redirect result immediately when page loads
69
- document.addEventListener("DOMContentLoaded", function () {
70
- console.log("Checking for auth redirect...");
71
147
  auth
72
148
  .getRedirectResult()
73
149
  .then((result) => {
74
150
  if (result && result.user) {
75
- console.log("Redirect authentication successful:", result.user);
76
151
  // Twitter or other redirect login was successful
77
152
  // Auth state observer will handle the UI update
78
153
  } else if (result) {
79
- console.log("Redirect completed but no user");
80
154
  }
81
155
  })
82
156
  .catch((error) => {
@@ -85,265 +159,338 @@ document.addEventListener("DOMContentLoaded", function () {
85
159
  alert(`Authentication error: ${error.message}`);
86
160
  }
87
161
  });
88
- });
89
-
90
- // DOM Elements
91
- const loginForm = document.getElementById("loginForm");
92
- const signupForm = document.getElementById("signupForm");
93
- const forgotPasswordForm = document.getElementById("forgotPasswordForm");
94
- const authContainer = document.getElementById("authContainer");
95
- const userAvatar = document.getElementById("userAvatar");
96
- const profileUserAvatar = document.querySelector(".profile-user-avatar");
97
-
98
- // Switch between login and signup
99
- document.getElementById("showSignup").addEventListener("click", (e) => {
100
- e.preventDefault();
101
- loginForm.style.display = "none";
102
- signupForm.style.display = "block";
103
- forgotPasswordForm.style.display = "none";
104
- });
105
-
106
- document.getElementById("showLogin").addEventListener("click", (e) => {
107
- e.preventDefault();
108
- signupForm.style.display = "none";
109
- loginForm.style.display = "block";
110
- forgotPasswordForm.style.display = "none";
111
- });
112
-
113
- // Show forgot password form
114
- document.getElementById("forgotPassword").addEventListener("click", (e) => {
115
- e.preventDefault();
116
- loginForm.style.display = "none";
117
- forgotPasswordForm.style.display = "block";
118
- });
119
-
120
- // Back to login from forgot password
121
- document.getElementById("backToLogin").addEventListener("click", () => {
122
- forgotPasswordForm.style.display = "none";
123
- loginForm.style.display = "block";
124
- document.getElementById("resetSuccess").style.display = "none";
125
- });
126
-
127
- // Handle reset password form submission
128
- document.getElementById("resetPasswordForm").addEventListener("submit", (e) => {
129
- e.preventDefault();
130
- const email = document.getElementById("resetEmail").value;
131
162
 
132
- auth
133
- .sendPasswordResetEmail(email)
134
- .then(() => {
135
- // Show success message
136
- document.getElementById("resetSuccess").style.display = "block";
137
- document.getElementById("resetPasswordForm").reset();
138
-
139
- // Redirect after 3 seconds
140
- setTimeout(() => {
141
- window.location.href = window.location.origin; // Redirect to domain root
142
- }, 3000);
143
- })
144
- .catch((error) => {
145
- alert(`Error: ${error.message}`);
163
+ // DOM Elements
164
+ const loginForm = document.getElementById("loginForm");
165
+ const signupForm = document.getElementById("signupForm");
166
+ const forgotPasswordForm = document.getElementById("forgotPasswordForm");
167
+ const userAvatar = document.getElementById("userAvatar");
168
+ const profileUserAvatar = document.querySelector(".profile-user-avatar");
169
+
170
+ // Switch between login and signup
171
+ const showSignupBtn = document.getElementById("showSignup");
172
+ if (showSignupBtn) {
173
+ showSignupBtn.addEventListener("click", (e) => {
174
+ e.preventDefault();
175
+ if (loginForm) loginForm.style.display = "none";
176
+ if (signupForm) signupForm.style.display = "block";
177
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
146
178
  });
147
- });
148
-
149
- // Toggle password visibility
150
- document.getElementById("toggleLoginPassword").addEventListener("click", () => {
151
- const passwordInput = document.getElementById("loginPassword");
152
- passwordInput.type = passwordInput.type === "password" ? "text" : "password";
153
- });
154
-
155
- document
156
- .getElementById("toggleSignupPassword")
157
- .addEventListener("click", () => {
158
- const passwordInput = document.getElementById("signupPassword");
159
- passwordInput.type =
160
- passwordInput.type === "password" ? "text" : "password";
161
- });
179
+ }
162
180
 
163
- // Email/Password Login
164
- document.getElementById("emailLoginForm").addEventListener("submit", (e) => {
165
- e.preventDefault();
166
- const email = document.getElementById("loginEmail").value;
167
- const password = document.getElementById("loginPassword").value;
181
+ const showLoginBtn = document.getElementById("showLogin");
182
+ if (showLoginBtn) {
183
+ showLoginBtn.addEventListener("click", (e) => {
184
+ e.preventDefault();
185
+ if (signupForm) signupForm.style.display = "none";
186
+ if (loginForm) loginForm.style.display = "block";
187
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
188
+ });
189
+ }
168
190
 
169
- auth
170
- .signInWithEmailAndPassword(email, password)
171
- .then((userCredential) => {
172
- // Signed in
173
- const user = userCredential.user;
174
- console.log("User logged in:", user);
175
- })
176
- .catch((error) => {
177
- alert(`Login error: ${error.message}`);
191
+ // Show forgot password form
192
+ const forgotPasswordBtn = document.getElementById("forgotPassword");
193
+ if (forgotPasswordBtn) {
194
+ forgotPasswordBtn.addEventListener("click", (e) => {
195
+ e.preventDefault();
196
+ if (loginForm) loginForm.style.display = "none";
197
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "block";
178
198
  });
179
- });
199
+ }
180
200
 
181
- // Email/Password Signup
182
- document.getElementById("emailSignupForm").addEventListener("submit", (e) => {
183
- e.preventDefault();
184
- const email = document.getElementById("signupEmail").value;
185
- const password = document.getElementById("signupPassword").value;
201
+ // Back to login from forgot password
202
+ const backToLoginBtn = document.getElementById("backToLogin");
203
+ if (backToLoginBtn) {
204
+ backToLoginBtn.addEventListener("click", () => {
205
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
206
+ if (loginForm) loginForm.style.display = "block";
207
+ const resetSuccess = document.getElementById("resetSuccess");
208
+ if (resetSuccess) resetSuccess.style.display = "none";
209
+ });
210
+ }
186
211
 
187
- auth
188
- .createUserWithEmailAndPassword(email, password)
189
- .then((userCredential) => {
190
- // Signed up
191
- const user = userCredential.user;
192
- console.log("User created:", user);
193
- })
194
- .catch((error) => {
195
- alert(`Signup error: ${error.message}`);
212
+ // Handle reset password form submission
213
+ const resetPasswordForm = document.getElementById("resetPasswordForm");
214
+ if (resetPasswordForm) {
215
+ resetPasswordForm.addEventListener("submit", (e) => {
216
+ e.preventDefault();
217
+ const resetEmail = document.getElementById("resetEmail");
218
+ if (!resetEmail) return;
219
+
220
+ const email = resetEmail.value;
221
+
222
+ // This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
223
+ const actionCodeSettings = {
224
+ url: "https://pdftoolkit-develop.netlify.app/",
225
+ handleCodeInApp: false,
226
+ };
227
+
228
+ auth
229
+ .sendPasswordResetEmail(email, actionCodeSettings)
230
+ .then(() => {
231
+ // Show success message
232
+ const resetSuccess = document.getElementById("resetSuccess");
233
+ if (resetSuccess) resetSuccess.style.display = "block";
234
+ resetPasswordForm.reset();
235
+ })
236
+ .catch((error) => {
237
+ alert(`Error: ${error.message}`);
238
+ });
196
239
  });
197
- });
240
+ }
198
241
 
199
- // Google Login
200
- document.getElementById("googleLogin").addEventListener("click", () => {
201
- const provider = new firebase.auth.GoogleAuthProvider();
202
- auth
203
- .signInWithPopup(provider)
204
- .then((result) => {
205
- console.log("Google login successful");
206
- })
207
- .catch((error) => {
208
- alert(`Google login error: ${error.message}`);
242
+ // Toggle password visibility
243
+ const toggleLoginPassword = document.getElementById("toggleLoginPassword");
244
+ if (toggleLoginPassword) {
245
+ toggleLoginPassword.addEventListener("click", () => {
246
+ const passwordInput = document.getElementById("loginPassword");
247
+ if (passwordInput) {
248
+ passwordInput.type =
249
+ passwordInput.type === "password" ? "text" : "password";
250
+ }
209
251
  });
210
- });
252
+ }
211
253
 
212
- document.getElementById("googleSignup").addEventListener("click", () => {
213
- const provider = new firebase.auth.GoogleAuthProvider();
214
- auth
215
- .signInWithPopup(provider)
216
- .then((result) => {
217
- console.log(result);
218
- console.log("Google signup successful");
219
- })
220
- .catch((error) => {
221
- alert(`Google signup error: ${error.message}`);
254
+ const toggleSignupPassword = document.getElementById("toggleSignupPassword");
255
+ if (toggleSignupPassword) {
256
+ toggleSignupPassword.addEventListener("click", () => {
257
+ const passwordInput = document.getElementById("signupPassword");
258
+ if (passwordInput) {
259
+ passwordInput.type =
260
+ passwordInput.type === "password" ? "text" : "password";
261
+ }
222
262
  });
223
- });
263
+ }
224
264
 
225
- // Facebook Login
226
- document.getElementById("facebookLogin").addEventListener("click", () => {
227
- const provider = new firebase.auth.FacebookAuthProvider();
228
- provider.addScope("email");
265
+ // Email/Password Login
266
+ const emailLoginForm = document.getElementById("emailLoginForm");
267
+ if (emailLoginForm) {
268
+ emailLoginForm.addEventListener("submit", (e) => {
269
+ e.preventDefault();
270
+ const loginEmail = document.getElementById("loginEmail");
271
+ const loginPassword = document.getElementById("loginPassword");
272
+ if (!loginEmail || !loginPassword) return;
273
+
274
+ const email = loginEmail.value;
275
+ const password = loginPassword.value;
276
+
277
+ auth
278
+ .signInWithEmailAndPassword(email, password)
279
+ .then((userCredential) => {
280
+ // Signed in
281
+ const user = userCredential.user;
282
+ })
283
+ .catch((error) => {
284
+ alert(`Login error: ${error.message}`);
285
+ });
286
+ });
287
+ }
229
288
 
230
- // Try popup instead of redirect for Facebook
231
- auth
232
- .signInWithPopup(provider)
233
- .then((result) => {
234
- console.log("Facebook login successful");
235
- })
236
- .catch((error) => {
237
- console.error("Facebook login error:", error);
238
- alert(`Facebook login error: ${error.message}`);
289
+ // Email/Password Signup
290
+ const emailSignupForm = document.getElementById("emailSignupForm");
291
+ if (emailSignupForm) {
292
+ emailSignupForm.addEventListener("submit", (e) => {
293
+ e.preventDefault();
294
+ const signupEmail = document.getElementById("signupEmail");
295
+ const signupPassword = document.getElementById("signupPassword");
296
+ if (!signupEmail || !signupPassword) return;
297
+
298
+ const email = signupEmail.value;
299
+ const password = signupPassword.value;
300
+
301
+ auth
302
+ .createUserWithEmailAndPassword(email, password)
303
+ .then((userCredential) => {
304
+ // Signed up
305
+ const user = userCredential.user;
306
+ })
307
+ .catch((error) => {
308
+ alert(`Signup error: ${error.message}`);
309
+ });
239
310
  });
240
- });
311
+ }
241
312
 
242
- // Twitter Login - Try using popup method first
243
- document.getElementById("twitterLogin").addEventListener("click", () => {
244
- console.log("Starting Twitter login...");
245
- const provider = new firebase.auth.TwitterAuthProvider();
313
+ // Google Login
314
+ const googleLoginBtn = document.getElementById("googleLogin");
315
+ if (googleLoginBtn) {
316
+ googleLoginBtn.addEventListener("click", () => {
317
+ const provider = new firebase.auth.GoogleAuthProvider();
318
+ auth
319
+ .signInWithPopup(provider)
320
+ .then((result) => {})
321
+ .catch((error) => {
322
+ alert(`Google login error: ${error.message}`);
323
+ });
324
+ });
325
+ }
246
326
 
247
- try {
248
- // Try popup method first as it provides better error feedback
249
- auth
250
- .signInWithPopup(provider)
251
- .then((result) => {
252
- console.log("Twitter login successful via popup");
253
- })
254
- .catch((error) => {
255
- console.error("Twitter popup error:", error);
256
-
257
- // If popup fails, fallback to redirect
258
- if (
259
- error.code === "auth/popup-blocked" ||
260
- error.code === "auth/popup-closed-by-user"
261
- ) {
262
- console.log("Popup blocked, trying redirect instead");
263
- auth.signInWithRedirect(provider).catch((redirectError) => {
264
- console.error("Twitter redirect error:", redirectError);
265
- alert(`Twitter login error: ${redirectError.message}`);
327
+ const googleSignupBtn = document.getElementById("googleSignup");
328
+ if (googleSignupBtn) {
329
+ googleSignupBtn.addEventListener("click", () => {
330
+ const provider = new firebase.auth.GoogleAuthProvider();
331
+ auth
332
+ .signInWithPopup(provider)
333
+ .then((result) => {})
334
+ .catch((error) => {
335
+ alert(`Google signup error: ${error.message}`);
336
+ });
337
+ });
338
+ }
339
+
340
+ // Facebook Login
341
+ const facebookLoginBtn = document.getElementById("facebookLogin");
342
+ if (facebookLoginBtn) {
343
+ facebookLoginBtn.addEventListener("click", () => {
344
+ const provider = new firebase.auth.FacebookAuthProvider();
345
+ provider.addScope("email");
346
+
347
+ // Try popup instead of redirect for Facebook
348
+ auth
349
+ .signInWithPopup(provider)
350
+ .then((result) => {})
351
+ .catch((error) => {
352
+ console.error("Facebook login error:", error);
353
+ alert(`Facebook login error: ${error.message}`);
354
+ });
355
+ });
356
+ }
357
+
358
+ // Twitter Login - Try using popup method first
359
+ const twitterLoginBtn = document.getElementById("twitterLogin");
360
+ if (twitterLoginBtn) {
361
+ twitterLoginBtn.addEventListener("click", () => {
362
+ const provider = new firebase.auth.TwitterAuthProvider();
363
+
364
+ try {
365
+ // Try popup method first as it provides better error feedback
366
+ auth
367
+ .signInWithPopup(provider)
368
+ .then((result) => {})
369
+ .catch((error) => {
370
+ console.error("Twitter popup error:", error);
371
+
372
+ // If popup fails, fallback to redirect
373
+ if (
374
+ error.code === "auth/popup-blocked" ||
375
+ error.code === "auth/popup-closed-by-user"
376
+ ) {
377
+ auth.signInWithRedirect(provider).catch((redirectError) => {
378
+ console.error("Twitter redirect error:", redirectError);
379
+ alert(`Twitter login error: ${redirectError.message}`);
380
+ });
381
+ } else {
382
+ alert(`Twitter login error: ${error.message}`);
383
+ }
266
384
  });
267
- } else {
268
- alert(`Twitter login error: ${error.message}`);
269
- }
270
- });
271
- } catch (e) {
272
- console.error("Exception during Twitter login:", e);
385
+ } catch (e) {
386
+ console.error("Exception during Twitter login:", e);
387
+ }
388
+ });
273
389
  }
274
- });
275
390
 
276
- // Logout
277
- document.getElementById("logoutBtn").addEventListener("click", () => {
278
- auth
279
- .signOut()
280
- .then(() => {
281
- document.querySelector(".user-profile-header").style.display = "none";
282
- window.location.reload();
283
- console.log("User signed out");
284
- })
285
- .catch((error) => {
286
- alert(`Logout error: ${error.message}`);
391
+ // Logout
392
+ const logoutBtn = document.getElementById("logoutBtn");
393
+ if (logoutBtn) {
394
+ logoutBtn.addEventListener("click", () => {
395
+ auth
396
+ .signOut()
397
+ .then(() => {
398
+ const userProfileHeader = document.querySelector(
399
+ ".user-profile-header"
400
+ );
401
+ if (userProfileHeader) userProfileHeader.style.display = "none";
402
+ window.location.reload();
403
+ })
404
+ .catch((error) => {
405
+ alert(`Logout error: ${error.message}`);
406
+ });
287
407
  });
288
- });
408
+ }
409
+
410
+ // Auth state observer
411
+ auth.onAuthStateChanged((user) => {
412
+ if (user) {
413
+ const email = user.email || "No email available";
414
+ const loggedInUserEmail = document.querySelector(".logged-in-user-email");
415
+ if (loggedInUserEmail) loggedInUserEmail.textContent = email;
416
+
417
+ let displayName =
418
+ user.displayName || (user.email ? user.email.split("@")[0] : "User");
419
+
420
+ // Special handling for Twitter users who might not have email
421
+ if (
422
+ user.providerData[0].providerId === "twitter.com" &&
423
+ !user.displayName
424
+ ) {
425
+ displayName = user.providerData[0].uid;
426
+ }
289
427
 
290
- // Auth state observer
291
- auth.onAuthStateChanged((user) => {
292
- console.log(
293
- "Auth state changed:",
294
- user ? "User logged in" : "User logged out"
295
- );
428
+ if (sideModal) {
429
+ sideModal.style.display = "none";
430
+ sideModal.style.right = "-90%";
431
+ }
296
432
 
297
- if (user) {
298
- console.log(user);
433
+ if (modalOverlayy) {
434
+ modalOverlayy.style.display = "none";
435
+ }
299
436
 
300
- const email = user.email || "No email available";
301
- document.querySelector(".logged-in-user-email").textContent = email;
302
- let displayName =
303
- user.displayName || (user.email ? user.email.split("@")[0] : "User");
437
+ const loggedInUsername = document.querySelector(".logged-in-username");
438
+ if (loggedInUsername) loggedInUsername.textContent = displayName;
304
439
 
305
- // Special handling for Twitter users who might not have email
306
- if (
307
- user.providerData[0].providerId === "twitter.com" &&
308
- !user.displayName
309
- ) {
310
- displayName = user.providerData[0].uid;
311
- }
440
+ const loginModalButton = document.querySelector(".login-modal-button");
441
+ if (loginModalButton) loginModalButton.style.display = "none";
442
+
443
+ // Set initials for avatar
444
+ const initials = displayName
445
+ .split(" ")
446
+ .map((n) => n[0])
447
+ .join("")
448
+ .toUpperCase()
449
+ .substring(0, 2);
312
450
 
313
- console.log("Provider:", user.providerData[0].providerId);
314
- console.log("Display name:", displayName);
315
- modal.style.display = "none";
316
- modal.style.right = "-90%";
317
- modalOverlay.style.display = "none";
318
- document.querySelector(".logged-in-username").textContent = displayName;
319
- document.querySelector(".login-modal-button").style.display = "none";
320
-
321
- // Set initials for avatar
322
- const initials = displayName
323
- .split(" ")
324
- .map((n) => n[0])
325
- .join("")
326
- .toUpperCase()
327
- .substring(0, 2);
328
- document.getElementById("profileButton").textContent = initials;
329
- profileUserAvatar.textContent = initials;
330
- document.querySelector(".user-profile-header").style.display = "block";
331
-
332
- userAvatar.textContent = initials;
333
- userAvatar.style.display = "flex";
334
- if (window.location.pathname === "/profile") {
335
- document.querySelector(".user-profile-section").style.display = "flex";
336
- document.querySelector(".profile-login-container").style.display = "none";
337
- document.querySelector(".avatar-large").textContent = initials;
338
- document.querySelector("#user-email-input").value = email;
339
- document.querySelector(".username-input").value = displayName;
340
-
341
- console.log("You are on the profile page.");
451
+ if (profileButton) profileButton.textContent = initials;
452
+ if (profileUserAvatar) profileUserAvatar.textContent = initials;
453
+
454
+ const userProfileHeader = document.querySelector(".user-profile-header");
455
+ if (userProfileHeader) userProfileHeader.style.display = "block";
456
+
457
+ if (userAvatar) {
458
+ userAvatar.textContent = initials;
459
+ userAvatar.style.display = "flex";
460
+ }
461
+
462
+ if (window.location.pathname === "/profile") {
463
+ const userProfileSection = document.querySelector(
464
+ ".user-profile-section"
465
+ );
466
+ if (userProfileSection) userProfileSection.style.display = "flex";
467
+
468
+ const profileLoginContainer = document.querySelector(
469
+ ".profile-login-container"
470
+ );
471
+ if (profileLoginContainer) profileLoginContainer.style.display = "none";
472
+
473
+ const avatarLarge = document.querySelector(".avatar-large");
474
+ if (avatarLarge) avatarLarge.textContent = initials;
475
+
476
+ const userEmailInput = document.querySelector("#user-email-input");
477
+ if (userEmailInput) userEmailInput.value = email;
478
+
479
+ const usernameInput = document.querySelector(".username-input");
480
+ if (usernameInput) usernameInput.value = displayName;
481
+ }
482
+ } else {
483
+ if (userAvatar) userAvatar.style.display = "none";
484
+ if (loginForm) loginForm.style.display = "block";
485
+ if (signupForm) signupForm.style.display = "none";
486
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
342
487
  }
343
- } else {
344
- userAvatar.style.display = "none";
345
- loginForm.style.display = "block";
346
- signupForm.style.display = "none";
347
- forgotPasswordForm.style.display = "none";
348
- }
349
- });
488
+ });
489
+ }
490
+
491
+ // Initialize the app
492
+ if (document.readyState === "loading") {
493
+ document.addEventListener("DOMContentLoaded", loadFirebaseConfig);
494
+ } else {
495
+ loadFirebaseConfig();
496
+ }