feat: кнопка «Админ» в чате — только для role=admin
Декодирует JWT payload (base64), показывает кнопку если role=admin. Для обычных users — скрыта. API проверяет role на сервере. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+13
-1
@@ -119,6 +119,7 @@ body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Robo
|
||||
<div id="header">
|
||||
<h1>Сметный ИИ-ассистент</h1>
|
||||
<div class="header-actions">
|
||||
<button id="btn-admin" style="display:none" onclick="window.open('/admin','_blank')">Админ</button>
|
||||
<button onclick="window.open('/batch3','_blank')">Пакетная</button>
|
||||
<button onclick="showSessions()">История</button>
|
||||
<button onclick="resetSession()">Новый диалог</button>
|
||||
@@ -166,8 +167,18 @@ const urlTab = new URLSearchParams(window.location.search).get('tab');
|
||||
let tabId = urlTab || sessionStorage.getItem('tabId') || crypto.randomUUID();
|
||||
sessionStorage.setItem('tabId', tabId);
|
||||
|
||||
function checkAdmin() {
|
||||
try {
|
||||
if (!token) return;
|
||||
const payload = JSON.parse(atob(token.split('.')[1]));
|
||||
if (payload.role === 'admin') {
|
||||
document.getElementById('btn-admin').style.display = '';
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// --- Init ---
|
||||
if (token) showChat(); else showLogin();
|
||||
if (token) { checkAdmin(); showChat(); } else showLogin();
|
||||
|
||||
function showLogin() {
|
||||
document.getElementById('login-screen').style.display = 'flex';
|
||||
@@ -195,6 +206,7 @@ async function doLogin(e) {
|
||||
const data = await r.json();
|
||||
token = data.token;
|
||||
localStorage.setItem('token', token);
|
||||
checkAdmin();
|
||||
showChat();
|
||||
addMsg('system', 'Добро пожаловать! Напишите вопрос или прикрепите файл.');
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user