This commit is contained in:
@ -7,21 +7,16 @@ import { exportPage } from './pages/export.js';
|
||||
import { usersPage } from './pages/users.js';
|
||||
import { assignmentsPage } from './pages/assignments.js';
|
||||
import { clientsPage } from './pages/clients.js';
|
||||
import {
|
||||
isLoggedIn,
|
||||
getRole,
|
||||
getUser,
|
||||
canEdit,
|
||||
authGuard as createAuthGuard,
|
||||
roleGuard as createRoleGuard,
|
||||
} from './auth-state.js';
|
||||
|
||||
// Auth state
|
||||
export function isLoggedIn() {
|
||||
return !!localStorage.getItem('qdb_token');
|
||||
}
|
||||
export function getRole() {
|
||||
return localStorage.getItem('qdb_role') || '';
|
||||
}
|
||||
export function getUser() {
|
||||
return localStorage.getItem('qdb_user') || '';
|
||||
}
|
||||
export function canEdit() {
|
||||
const r = getRole();
|
||||
return r === 'admin' || r === 'supervisor';
|
||||
}
|
||||
export { isLoggedIn, getRole, getUser, canEdit };
|
||||
|
||||
export function showToast(message, type = 'info') {
|
||||
const container = document.getElementById('toastContainer');
|
||||
@ -37,10 +32,7 @@ export function showToast(message, type = 'info') {
|
||||
}
|
||||
|
||||
function authGuard(handler) {
|
||||
return (params) => {
|
||||
if (!isLoggedIn()) { navigate('#/login'); return; }
|
||||
return handler(params);
|
||||
};
|
||||
return createAuthGuard(navigate, handler);
|
||||
}
|
||||
|
||||
function updateNav() {
|
||||
@ -70,11 +62,7 @@ function updateNav() {
|
||||
}
|
||||
|
||||
function roleGuard(roles, handler) {
|
||||
return (params) => {
|
||||
if (!isLoggedIn()) { navigate('#/login'); return; }
|
||||
if (!roles.includes(getRole())) { navigate('#/'); return; }
|
||||
return handler(params);
|
||||
};
|
||||
return createRoleGuard(navigate, roles, handler);
|
||||
}
|
||||
|
||||
// Routes
|
||||
|
||||
Reference in New Issue
Block a user