dc
unknown
plain_text
a month ago
1.0 kB
0
Indexable
Never
const fetchUserInfo = async () => { const token = localStorage.getItem('token'); const userId = localStorage.getItem('userId'); if (!token || !userId) { setUser(null); return; } try { const response = await fetch(`${BASE_URL}/api/staff-member/member/getById/${userId}`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, }); if (!response.ok) { throw new Error(`Failed to fetch user info: ${response.statusText}`); } const userData = await response.json(); console.log("User Data:", userData); // Kiểm tra dữ liệu ở đây // Xác nhận các trường const { fullName, avatar } = userData; if (fullName && avatar) { setUser(userData); } else { console.error("Missing data fields:", userData); setUser(null); } } catch (error) { console.error("Error fetching user info:", error); setUser(null); } };
Leave a Comment