fix(auth): 401 dal backend svuota la sessione e segnala session_expired (#25)

api_client._handle_response: su 401 pulisce la sessione Flask e marca
g.session_expired. Un solo after_request (app.py) trasforma le pagine HTML
rimaste in piedi con un errore generico in un redirect al login con flash;
le route JSON/AJAX che già inoltrano il dict di api_client (measure.py,
statistics.py) ricevono session_expired nel corpo insieme al 401.
Backend (riuso della key, bcrypt a tempo costante) resta al lotto A2.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 22:33:40 +02:00
parent ac9bc14f5d
commit 1fee29358f
5 changed files with 155 additions and 7 deletions
+5 -2
View File
@@ -481,10 +481,13 @@ def save_measurement():
if resp.get("error"):
status_code = resp.get("status_code", 500)
return jsonify({
error_body = {
"error": True,
"detail": resp.get("detail", _("Errore nel salvataggio")),
}), status_code if status_code >= 400 else 500
}
if resp.get("session_expired"):
error_body["session_expired"] = True
return jsonify(error_body), status_code if status_code >= 400 else 500
return jsonify(resp), 201