homebox/frontend/lib/api/public.ts

48 lines
920 B
TypeScript
Raw Normal View History

import { BaseAPI, route } from "./base";
2022-09-01 14:32:03 -08: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-03 18:42:03 -08:00
export type StatusResult = {
health: boolean;
versions: string[];
title: string;
message: string;
};
2022-09-01 14:32:03 -08:00
export class PublicApi extends BaseAPI {
2022-09-03 18:42:03 -08:00
public status() {
return this.http.get<StatusResult>({ url: route("/status") });
2022-09-03 18:42:03 -08:00
}
2022-09-01 14:32:03 -08:00
public login(username: string, password: string) {
2022-09-08 22:05:23 -08:00
return this.http.post<LoginPayload, LoginResult>({
url: route("/users/login"),
2022-09-08 22:05:23 -08:00
body: {
username,
password,
},
2022-09-01 17:52:40 -08:00
});
2022-09-01 14:32:03 -08:00
}
2022-09-08 22:05:23 -08:00
public register(body: RegisterPayload) {
return this.http.post<RegisterPayload, LoginResult>({ url: route("/users/register"), body });
2022-09-01 14:32:03 -08:00
}
}