Initial commit

This commit is contained in:
2026-06-30 17:06:06 +02:00
commit d0bb893522
19 changed files with 1333 additions and 0 deletions

44
ts/login.ts Normal file
View File

@@ -0,0 +1,44 @@
import { BambuddyAddress } from './constants';
export async function login(
username: string,
password: string,
): Promise<LoginResponse | null> {
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;
};
}