Files
Aegis/frontend/src/api/auth.ts
Kitos a4a2adccee
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
feat(phase-39): role-based access control overhaul + forced password change
- Add must_change_password field to User model with migration b023

- Add POST /auth/change-password endpoint with password policy validation

- Add require_password_changed dependency to block requests until password is changed

- Add ChangePasswordModal with live password policy checklist (forced on first login)

- Show password policy in CreateUserModal and EditUserModal

- Fix backend permissions: tests, campaigns, templates, reports, evidence, worklogs

- red_tech/blue_tech: execute only, cannot create tests/campaigns/templates

- red_lead/blue_lead: create/edit tests/campaigns/templates, generate reports, no system access

- viewer: read-only everywhere, can generate reports

- Fix frontend role checks across TestDetailPage, TestDetailHeader, TeamTabs, TestsPage, CampaignsPage, CampaignDetailPage, Sidebar
2026-02-18 10:37:02 +01:00

48 lines
1.2 KiB
TypeScript

import client from "./client";
import type { User } from "../types/models";
/**
* Authenticate the user.
*
* The backend sets an HttpOnly cookie with the JWT — no token is stored
* in JavaScript memory or localStorage.
*/
export async function login(
username: string,
password: string,
): Promise<void> {
const params = new URLSearchParams();
params.append("username", username);
params.append("password", password);
await client.post("/auth/login", params, {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
}
/** Clear the authentication cookie on the server. */
export async function logout(): Promise<void> {
try {
await client.post("/auth/logout");
} catch {
// Best-effort — the cookie will expire anyway
}
}
/** Fetch the currently authenticated user profile. */
export async function getMe(): Promise<User> {
const { data } = await client.get<User>("/auth/me");
return data;
}
/** Change the current user's password. */
export async function changePassword(
currentPassword: string,
newPassword: string,
): Promise<void> {
await client.post("/auth/change-password", {
current_password: currentPassword,
new_password: newPassword,
});
}