2026-06-21 15:03:43 +03:00
|
|
|
import { apiClient } from './client';
|
|
|
|
|
|
2026-06-21 17:15:26 +03:00
|
|
|
export interface ActiveSession {
|
|
|
|
|
id: number;
|
2026-06-21 15:03:43 +03:00
|
|
|
device: string;
|
|
|
|
|
ip: string | null;
|
|
|
|
|
at: string | null;
|
|
|
|
|
current: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AccountSecurity {
|
|
|
|
|
last_password_change_at: string | null;
|
2026-06-21 17:15:26 +03:00
|
|
|
sessions: ActiveSession[];
|
2026-06-21 15:03:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ChangePasswordPayload {
|
|
|
|
|
current_password: string;
|
|
|
|
|
password: string;
|
|
|
|
|
password_confirmation: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** GET /api/account/security — дата последней смены пароля + недавние входы. */
|
|
|
|
|
export async function getAccountSecurity(): Promise<AccountSecurity> {
|
|
|
|
|
const { data } = await apiClient.get<AccountSecurity>('/api/account/security');
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** POST /api/account/change-password — смена пароля. Возвращает ISO-дату смены. */
|
|
|
|
|
export async function changePassword(payload: ChangePasswordPayload): Promise<string> {
|
|
|
|
|
const { data } = await apiClient.post<{ last_password_change_at: string }>(
|
|
|
|
|
'/api/account/change-password',
|
|
|
|
|
payload,
|
|
|
|
|
);
|
|
|
|
|
return data.last_password_change_at;
|
|
|
|
|
}
|
2026-06-21 17:15:26 +03:00
|
|
|
|
|
|
|
|
/** DELETE /api/account/sessions/{id} — завершить (отозвать) сессию. */
|
|
|
|
|
export async function revokeSession(id: number): Promise<void> {
|
|
|
|
|
await apiClient.delete(`/api/account/sessions/${id}`);
|
|
|
|
|
}
|