From a7f9072aa694949e750c3c93ec91d83fac60a248 Mon Sep 17 00:00:00 2001 From: 65160381 <65160381@go.buu.ac.th> Date: Tue, 25 Mar 2025 04:04:17 +0700 Subject: [PATCH] 9.8 --- public/index.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/public/index.html b/public/index.html index 6366563..6177253 100644 --- a/public/index.html +++ b/public/index.html @@ -99,6 +99,24 @@ alert(`${productName} added to cart!`); } + async function displayUsername() { + try { + const response = await fetch('/api/getUser'); // Endpoint to get the user's email + if (response.status === 401) { + console.log('User not logged in'); + document.getElementById('welcome-message').innerText = 'Please log in'; + } else { + const user = await response.json(); + document.getElementById('welcome-message').innerText = `Welcome, ${user.email}`; // Display email here + } + } catch (error) { + console.log('Error fetching user info:', error); + } + } + + // เรียกใช้ฟังก์ชันเมื่อหน้าเว็บโหลดเสร็จ + window.onload = displayUsername; + // ฟังก์ชันอัปเดตจำนวนสินค้าที่อยู่ในตะกร้า function updateCart() { let cart = JSON.parse(localStorage.getItem('cart')) || []; -- GitLab