Add avatar dropdown in header

This commit is contained in:
Tim
2025-07-05 14:13:35 +08:00
parent 94a1b4a237
commit bd043350b6
4 changed files with 110 additions and 3 deletions

View File

@@ -14,6 +14,20 @@ export function clearToken() {
localStorage.removeItem(TOKEN_KEY)
}
export async function fetchCurrentUser() {
const token = getToken()
if (!token) return null
try {
const res = await fetch(`${API_BASE_URL}/api/users/me`, {
headers: { Authorization: `Bearer ${token}` }
})
if (!res.ok) return null
return await res.json()
} catch (e) {
return null
}
}
export function isLogin() {
const token = getToken()
console.log('token', token)