Create base main page
This commit is contained in:
@ -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",
|
||||
},
|
||||
});
|
||||
|
@ -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
|
||||
*
|
||||
|
26
geneit_app/src/api/UserApi.ts
Normal file
26
geneit_app/src/api/UserApi.ts
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user