feat: add auth UI to nav — login/logout button, bodega link
Shows business name + logout button when authenticated. Shows login link when not authenticated. Adds bodega to nav links. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,12 +21,23 @@
|
||||
if ((h === '/admin.html' || h === '/admin') && (p === '/admin.html' || p === '/admin')) return true;
|
||||
if ((h === '/diagramas' || h === '/diagrams.html') && (p === '/diagramas' || p === '/diagrams.html')) return true;
|
||||
if ((h === '/customer-landing.html') && (p === '/customer-landing.html')) return true;
|
||||
if ((h === '/captura') && (p === '/captura')) return true;
|
||||
if ((h === '/pos') && (p === '/pos')) return true;
|
||||
if ((h === '/cuentas') && (p === '/cuentas')) return true;
|
||||
if ((h === '/tienda') && (p === '/tienda')) return true;
|
||||
if ((h === '/bodega') && (p === '/bodega')) return true;
|
||||
if ((h === '/demo' || h === '/demo.html') && (p === '/demo' || p === '/demo.html')) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
var navLinks = [
|
||||
{ label: 'Cat\u00e1logo', href: '/' },
|
||||
{ label: 'Diagramas', href: '/diagramas' },
|
||||
{ label: 'Demo', href: '/demo' },
|
||||
{ label: 'Tienda', href: '/tienda' },
|
||||
{ label: 'Cat\u00e1logo', href: '/index.html' },
|
||||
{ label: 'Captura', href: '/captura' },
|
||||
{ label: 'POS', href: '/pos' },
|
||||
{ label: 'Cuentas', href: '/cuentas' },
|
||||
{ label: 'Bodega', href: '/bodega' },
|
||||
{ label: 'Admin', href: '/admin' }
|
||||
];
|
||||
|
||||
@@ -99,6 +110,16 @@
|
||||
+ '">'
|
||||
+ linksHTML
|
||||
+ '</nav>'
|
||||
// Auth section
|
||||
+ '<div id="nav-auth" style="display:flex;align-items:center;gap:0.75rem;flex-shrink:0;">'
|
||||
+ '<span id="nav-user-name" style="color:var(--text-secondary);font-size:0.85rem;"></span>'
|
||||
+ '<a id="nav-auth-btn" href="/login.html" style="'
|
||||
+ 'text-decoration:none;font-size:0.85rem;font-weight:500;'
|
||||
+ 'color:var(--bg);background:var(--accent);'
|
||||
+ 'padding:0.4rem 1rem;border-radius:6px;'
|
||||
+ 'transition:opacity 0.2s;'
|
||||
+ '">Iniciar Sesi\u00f3n</a>'
|
||||
+ '</div>'
|
||||
+ '</div>'
|
||||
+ '</header>';
|
||||
|
||||
@@ -106,4 +127,29 @@
|
||||
if (target) {
|
||||
target.innerHTML = html;
|
||||
}
|
||||
|
||||
// Auth state
|
||||
var token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
try {
|
||||
var payload = JSON.parse(atob(token.split('.')[1]));
|
||||
var nameEl = document.getElementById('nav-user-name');
|
||||
var btnEl = document.getElementById('nav-auth-btn');
|
||||
if (nameEl && payload.business_name) {
|
||||
nameEl.textContent = payload.business_name;
|
||||
} else if (nameEl) {
|
||||
nameEl.textContent = payload.role || '';
|
||||
}
|
||||
if (btnEl) {
|
||||
btnEl.textContent = 'Salir';
|
||||
btnEl.href = '#';
|
||||
btnEl.onclick = function(e) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('refresh_token');
|
||||
window.location.href = '/login.html';
|
||||
};
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user