added child endpoint, ability to add and edit child as well as auto redirect to add-child page when user without child accesses home page
This commit is contained in:
@@ -129,6 +129,7 @@
|
||||
<div class="menu-backdrop" id="menuBackdrop"></div>
|
||||
|
||||
<div class="menu-overlay" id="menuOverlay">
|
||||
<div class="menu-item" id="menuAddChild">👶 Add Child</div>
|
||||
<div class="menu-item logout" id="menuLogout">🚪 Logout</div>
|
||||
</div>
|
||||
|
||||
@@ -160,6 +161,10 @@
|
||||
burgerMenu.addEventListener("click", toggleMenu);
|
||||
menuBackdrop.addEventListener("click", closeMenu);
|
||||
|
||||
document.getElementById("menuAddChild").addEventListener("click", () => {
|
||||
window.location.href = "/add-child.html";
|
||||
});
|
||||
|
||||
document.getElementById("menuLogout").addEventListener("click", () => {
|
||||
closeMenu();
|
||||
logout();
|
||||
@@ -187,14 +192,29 @@
|
||||
}
|
||||
})
|
||||
.then((user) => {
|
||||
// Show authenticated content
|
||||
document.getElementById("content").innerHTML = `
|
||||
// Check if user has any children
|
||||
return fetch("/api/children", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((children) => {
|
||||
// If no children, redirect to add-child page
|
||||
if (children.length === 0) {
|
||||
window.location.href = "/add-child.html";
|
||||
return;
|
||||
}
|
||||
|
||||
// Show authenticated content
|
||||
document.getElementById("content").innerHTML = `
|
||||
<h1>Welcome to Baby Monitor!</h1>
|
||||
<div class="user-info">
|
||||
<p><strong>Logged in as:</strong> ${username}</p>
|
||||
</div>
|
||||
<p>Your session is active.</p>
|
||||
`;
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
|
||||
Reference in New Issue
Block a user