fix: use shared auth-guard.js on settings.html
This commit is contained in:
parent
ebe8b3be59
commit
a40232e2b5
1 changed files with 1 additions and 19 deletions
|
|
@ -291,24 +291,6 @@
|
||||||
el.textContent = msg;
|
el.textContent = msg;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script src="js/auth-guard.js"></script>
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const r = await fetch('/api/v1/auth/me', { credentials: 'include' });
|
|
||||||
if (r.ok) {
|
|
||||||
const u = await r.json();
|
|
||||||
const name = u.display_name || u.username || 'User';
|
|
||||||
document.getElementById('userName').textContent = name;
|
|
||||||
document.getElementById('userAvatar').textContent = name[0].toUpperCase();
|
|
||||||
const roleEl = document.getElementById('userRole');
|
|
||||||
if (roleEl) roleEl.textContent = u.role || '';
|
|
||||||
}
|
|
||||||
} catch (_) {}
|
|
||||||
document.getElementById('logoutBtn').onclick = async () => {
|
|
||||||
try { await fetch('/api/v1/auth/logout', { method: 'POST', credentials: 'include' }); } catch (_) {}
|
|
||||||
location.href = 'login.html';
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue