import { BambuddyAddress } from './constants'; export async function login( username: string, password: string, ): Promise { const request = await fetch(`${BambuddyAddress}/api/v1/auth/login`, { headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username: username, password: password, }), method: 'POST', }); const response = await request.json(); if (response?.detail != null) { console.error(`Login failed: ${response.detail}`); return null; } return response as LoginResponse; } export interface LoginResponse { access_token: string; token_type: string; user: { auth_source: string; created_at: string; email: string; groups: { id: number; name: string }[]; id: number; is_active: boolean; is_admin: boolean; permissions: string[]; role: string; username: string; }; }