Create base main page

This commit is contained in:
2023-06-09 11:19:40 +02:00
parent d55718f4de
commit 3ca941bd57
6 changed files with 166 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import { AuthApi } from "./AuthApi";
interface APIResponse {
data: any;
status: number;
@ -32,6 +34,7 @@ export class APIClient {
method: args.method,
body: args.jsonData ? JSON.stringify(args.jsonData) : undefined,
headers: {
"X-auth-token": AuthApi.SignedIn ? AuthApi.AuthToken : "none",
"Content-Type": args.jsonData ? "application/json" : "text/plain",
},
});

View File

@ -13,6 +13,14 @@ export class AuthApi {
static authStatus = atom(this.SignedIn);
/**
* Get user auth token
*/
static get AuthToken(): string {
if (!this.SignedIn) throw new Error("User is not authenticated!");
return sessionStorage.getItem(TokenStateKey)!;
}
/**
* Start OpenID login
*

View File

@ -0,0 +1,26 @@
import { APIClient } from "./ApiClient";
export interface User {
id: number;
name: string;
email: string;
time_create: number;
time_activate: number;
active: boolean;
admin: boolean;
has_password: boolean;
}
export class UserApi {
/**
* Get current user information
*/
static async GetUserInfo(): Promise<User> {
return (
await APIClient.exec({
uri: "/user/info",
method: "GET",
})
).data;
}
}