homebox/frontend/lib/api/public.ts

48 lines
920 B
TypeScript
Raw Normal View History

2022-09-05 00:55:52 +00:00
import { BaseAPI, route } from './base';
2022-09-01 22:32:03 +00:00
export type LoginResult = {
token: string;
expiresAt: string;
};
export type LoginPayload = {
username: string;
password: string;
};
export type RegisterPayload = {
user: {
email: string;
password: string;
name: string;
};
groupName: string;
};
2022-09-04 02:42:03 +00:00
export type StatusResult = {
health: boolean;
versions: string[];
title: string;
message: string;
};
2022-09-01 22:32:03 +00:00
export class PublicApi extends BaseAPI {
2022-09-04 02:42:03 +00:00
public status() {
2022-09-09 06:05:23 +00:00
return this.http.get<StatusResult>({ url: route('/status') });
2022-09-04 02:42:03 +00:00
}
2022-09-01 22:32:03 +00:00
public login(username: string, password: string) {
2022-09-09 06:05:23 +00:00
return this.http.post<LoginPayload, LoginResult>({
url: route('/users/login'),
body: {
username,
password,
},
2022-09-02 01:52:40 +00:00
});
2022-09-01 22:32:03 +00:00
}
2022-09-09 06:05:23 +00:00
public register(body: RegisterPayload) {
return this.http.post<RegisterPayload, LoginResult>({ url: route('/users/register'), body });
2022-09-01 22:32:03 +00:00
}
}