Initial commit
This commit is contained in:
44
ts/login.ts
Normal file
44
ts/login.ts
Normal 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user