feat: add logout functionality and auto-logout on 401 responses

Add AUTH_EXPIRED_EVENT constant and dispatch event on 401 responses in API client, clearing stored token. Add handleLogout function to App component and wire up event listener to trigger logout on auth expiration. Pass onLogout prop to Layout component and add Logout button to topbar-actions. Update CSS to apply flex layout to topbar-actions and make responsive. Add backend hostname and network aliases in docker-compose to ensure consistent
This commit is contained in:
nessi committed 2026-03-17 19:39:13 +01:00
1 parent 61d2b4b25c
commit e2362c6033
5 files changed
+40 -7

No files matched your search

+5
View File
@@ -1,4 +1,5 @@
const API_BASE = import.meta.env.VITE_API_BASE_URL ?? "/api/v1";
export const AUTH_EXPIRED_EVENT = "nexavpn-admin-auth-expired";
export type User = {
id: string;
@@ -85,6 +86,10 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
});
if (!response.ok) {
if (response.status === 401) {
localStorage.removeItem("nexavpn_admin_token");
window.dispatchEvent(new Event(AUTH_EXPIRED_EVENT));
}
throw new Error(`Request failed: ${response.status}`);
}