diff --git a/geneit_app/src/App.tsx b/geneit_app/src/App.tsx index 2750f97..eebd46e 100644 --- a/geneit_app/src/App.tsx +++ b/geneit_app/src/App.tsx @@ -6,6 +6,7 @@ import { BaseLoginPage } from "./widgets/BaseLoginpage"; import { LoginRoute } from "./routes/auth/LoginRoute"; import { OIDCCbRoute } from "./routes/auth/OIDCCbRoute"; import { useAtom } from "jotai"; +import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage"; function App() { const [signedIn] = useAtom(AuthApi.authStatus); @@ -13,7 +14,7 @@ function App() { return ( {signedIn ? ( - signed in

} /> + } /> ) : ( }> } /> diff --git a/geneit_app/src/api/ApiClient.ts b/geneit_app/src/api/ApiClient.ts index e5418b9..21637cf 100644 --- a/geneit_app/src/api/ApiClient.ts +++ b/geneit_app/src/api/ApiClient.ts @@ -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", }, }); diff --git a/geneit_app/src/api/AuthApi.ts b/geneit_app/src/api/AuthApi.ts index 1fb36af..a99db50 100644 --- a/geneit_app/src/api/AuthApi.ts +++ b/geneit_app/src/api/AuthApi.ts @@ -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 * diff --git a/geneit_app/src/api/UserApi.ts b/geneit_app/src/api/UserApi.ts new file mode 100644 index 0000000..85fb373 --- /dev/null +++ b/geneit_app/src/api/UserApi.ts @@ -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 { + return ( + await APIClient.exec({ + uri: "/user/info", + method: "GET", + }) + ).data; + } +} diff --git a/geneit_app/src/routes/auth/LoginRoute.tsx b/geneit_app/src/routes/auth/LoginRoute.tsx index 98ff777..a24a00f 100644 --- a/geneit_app/src/routes/auth/LoginRoute.tsx +++ b/geneit_app/src/routes/auth/LoginRoute.tsx @@ -103,6 +103,7 @@ export function LoginRoute(): React.ReactElement {
{ServerApi.Config.oidc_providers.map((p) => ( + + + + Profil + Déconnexion + +
+ + + + + ); +}