fix(auth): redirige a taller y limpia SW para usuarios workshop/mechanic
Some checks failed
CI / lint-and-test (3.11) (push) Has been cancelled
CI / lint-and-test (3.13) (push) Has been cancelled

- Agrega script inline en todas las plantillas (excepto login/workshop) que lee
  el rol del JWT y redirige a /pos/workshop si es workshop/mechanic.
- Desregistra el Service Worker antes de redirigir para forzar carga fresca
  de assets y evitar que menus antiguos permanezcan por cache.
- Actualiza labels de rol en auth_bp.py para taller y mecanico.

Tests: 35 passed
This commit is contained in:
2026-06-30 16:46:30 +00:00
parent 4d971dd1a4
commit 688ea8c70c
18 changed files with 205 additions and 1 deletions

View File

@@ -16,6 +16,18 @@
<link rel="shortcut icon" type="image/png" href="/pos/static/pwa/icon-192.png" />
<link rel="stylesheet" href="/pos/static/css/invoicing.css">
<script id="workshop-mechanic-redirect">
(function(){
var t=localStorage.getItem("pos_token");
if(!t)return;
try{var p=JSON.parse(atob(t.split(".")[1]));var r=(p.role||"").toLowerCase();
if((r==="workshop"||r==="mechanic")&&window.location.pathname!=="/pos/workshop"){
if("serviceWorker" in navigator){navigator.serviceWorker.getRegistrations().then(function(rs){rs.forEach(function(reg){reg.unregister();});});}
window.location.replace("/pos/workshop");
}
}catch(e){}
})();
</script>
</head>
<body>