Пользователь и вводится в систему и поступает на их панели на панели на рабочем месте. alt = "Desktop Dashboard" src = "https://i.sstatic.net/tkrabwyf.png"/>
Однако на мобильных устройствах (по крайней мере, на моем устройстве iOS), я пытаюсь войти в систему, и успешное состояние входа в систему приводит меня на панель, но ничего не загружается. Трудно понять, что вызывает проблему (я все еще учусь, так что, возможно, я не знаю функции консольной отладки, если она есть). < /p>
Что странно, так это то, что он меня входит в систему, поэтому браузер общается с Firebase Auth, но затем после этого ничего другого не приносит никакого другого. src = "https://i.sstatic.net/650mccdb.png"/>
Браузер iOS, похоже, не получает никаких данных, прошедших аут пользователя. В настоящее время у меня есть Firebase, инициализированная на глобальной теге, как показано здесь < /p>
let originalContent = "";
let lottieElement = null; // Store reference to the Lottie animation
let products = [];
window.fetchFirebaseConfig = async function() {
try {
// If already initialized, just return the Firestore instance
if (typeof window.firebase !== "undefined" && window.firebase.apps.length > 0) {
console.log("
return window.firebase.firestore();
}
// Otherwise, fetch the config from your Cloud Function
const response = await fetch("https://us-central1-project-name-remove ... baseConfig");
if (!response.ok) throw new Error("Failed to fetch Firebase configuration");
const firebaseConfig = await response.json();
window.firebase = firebase; // store Firebase globally
firebase.initializeApp(firebaseConfig);
window.auth = firebase.auth(); // store Auth globally
// 3. Enable Firestore offline persistence (wrap in its own try/catch)
try {
await firebase.firestore().enablePersistence();
console.log("
} catch (err) {
// If it fails (e.g., already started), log a warning but continue
console.warn("
}
window.db = firebase.firestore();
console.log("
return window.db;
} catch (error) {
console.error("
return null;
}
};
< /code>
document.addEventListener("DOMContentLoaded", async function () {
let db = null;
const searchInput = document.getElementById("searchInput");
const searchResults = document.getElementById("searchResults");
window.db = await fetchFirebaseConfig(); //
if (!window.db) {
console.error("
}
// ---------- Auth State Listener (Toggle Divs + Update User Fields) ----------
firebase.auth().onAuthStateChanged(async function(user) {
window.isAdmin = false;
if (user) {
try {
const adminDoc = await window.db.collection("admins").doc(user.uid).get();
window.isAdmin = adminDoc.exists;
console.log("
} catch (e) {
console.error("Error checking admin status:", e);
window.isAdmin = false;
}
}
const signedInDiv = document.getElementById("signedInDiv");
const signedOutDiv = document.getElementById("signedOutDiv");
const navProfilePic = document.getElementById("navProfilePic");
const navProfilePicImg = document.getElementById("navProfilePicImg");
const navInitials = document.getElementById("navInitials");
const userInitialsEl = document.getElementById("userInitials");
if (user) {
// User is signed in: show signedInDiv, hide signedOutDiv
if (signedOutDiv) signedOutDiv.style.display = "none";
// Update dynamic fields: first name, last name, company, and initials
const userNameEl = document.getElementById("userName1");
const userCompanyEl = document.getElementById("userCompany");
const userInitialsEl = document.getElementById("userInitials");
window.db.collection("users").doc(user.uid).get().then(function(docSnap) {
if (docSnap.exists) {
const userData = docSnap.data();
const firstName = userData.firstName || "";
const lastName = userData.lastName || "";
const company = userData.company || "";
const fullName = (firstName + " " + lastName).trim();
const initials = (firstName.charAt(0) + lastName.charAt(0)).toUpperCase();
const userPhotoURL = userData.profilePicture || "";
if (userNameEl) userNameEl.textContent = fullName;
if (userCompanyEl) userCompanyEl.textContent = company;
if (userInitialsEl) userInitialsEl.textContent = initials;
// Toggle between profile image and initials placeholder
if (userPhotoURL) {
// Use the firebase image for the default (ST logo) if available:
if (navProfilePicImg) {
navProfilePicImg.src = userPhotoURL;
navProfilePicImg.alt = fullName || "Profile Picture";
}
// Show the profile picture container and hide the initials
if (navProfilePic) navProfilePic.style.display = "block";
if (navInitials) navInitials.style.display = "none";
} else {
if (navProfilePic) navProfilePic.style.display = "none";
if (navInitials) navInitials.style.display = "block";
}
if (signedInDiv) signedInDiv.style.display = "block";
} else {
console.error("No Firestore document found for user:", user.uid);
}
}).catch(function(error) {
console.error("Error fetching user document:", error);
});
} else {
if (signedInDiv) signedInDiv.style.display = "none";
if (signedOutDiv) signedOutDiv.style.display = "block";
const userNameEl = document.getElementById("userName1");
const userCompanyEl = document.getElementById("userCompany");
const userInitialsEl = document.getElementById("userInitials");
if (userNameEl) userNameEl.textContent = "";
if (userCompanyEl) userCompanyEl.textContent = "";
if (userInitialsEl) userInitialsEl.textContent = "";
if (navProfilePic) navProfilePic.style.display = "none";
if (navInitials) navInitials.style.display = "none";
}
});
// ---------- Div Click Event Listeners (Redirect or Open regModal) ----------
const signedInDiv = document.getElementById("signedInDiv");
const signedOutDiv = document.getElementById("signedOutDiv");
if (signedInDiv) {
signedInDiv.addEventListener("click", function() {
if (firebase.auth().currentUser) {
window.location.href = '/dashboard/home';
}
});
}
if (signedOutDiv) {
signedOutDiv.addEventListener("click", function() {
if (!firebase.auth().currentUser && regModal) {
regModal.style.display = "flex";
}
});
}
< /code>
Dashboard Script below
console.log("Project Form script loaded."); // Top-level log to confirm script is running
document.addEventListener("DOMContentLoaded", async function () {
//document.getElementById("dashboardContent").style.display = "none";
// Wait for Firebase initialization
const db = await window.fetchFirebaseConfig();
if (!db) {
console.error("
return;
}
// Track the currently authenticated user (if any)
let currentUser = null;
firebase.auth().onAuthStateChanged(async (user) => {
currentUser = user;
if (!user) {
// Replace the page content with the not logged in message
document.getElementById("loading-spinner").style.display = "none";
document.getElementById("logoutButton").style.display = "none";
document.body.innerHTML = `
You are not logged in to see this /dashboard page.
Please log in or sign up to access your dashboard.
`;
} else {
// User is logged in, so reveal the dashboard content
console.log("Authenticated user:", user);
try {
// 1) Fetch the user doc to get first name and other data (removed for character count)
const docSnap = await db.collection("users").doc(user.uid).get();
if (docSnap.exists) {
const userData = docSnap.data();
// Update the welcome message with first name
const firstName = userData.firstName || "User";
document.getElementById("userName").innerText = `${firstName}`;
// If the user has a profile picture, set the img src:
if (userData.profilePicture) {
profileImageEl.src = userData.profilePicture;
profileImageEl.style.display = "block";
document.getElementById("profileInitialsContainer").style.display = "none"; // Hide the initials container
} else {
// No profile picture
profileImageEl.src = "";
profileImageEl.style.display = "none";
document.getElementById("profilePicContainer").style.display = "none"; // Hide the initials container
document.getElementById("profileInitialsContainer").style.display = "flex"; // Hide the initials container
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... ebase-auth