From 09314d3db061e4db675aee1ad60596439e9f83d2 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 4 Jul 2025 13:58:41 +0000 Subject: [PATCH] frontend: Move user stuff into an own file Signed-off-by: Michael Tremer --- frontend/src/api/auth.ts | 15 ++------------- frontend/src/api/users.ts | 21 +++++++++++++++++++++ frontend/src/composables/auth.ts | 2 +- frontend/src/stores/auth.ts | 4 ++-- frontend/src/types/User.ts | 10 ---------- 5 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 frontend/src/api/users.ts delete mode 100644 frontend/src/types/User.ts diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index 0b59190d..a956a91a 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -1,5 +1,6 @@ import api from "@/api" -import type { User } from "@/types/User" +import type { User } from "@/api/users" +import { fetchCurrentUser } from "@/api/users" interface AuthResponse { access_token: string; @@ -50,15 +51,3 @@ export async function authenticateUser(username: string, password: string): Prom throw new Error("Invalid username or password") } } - -/* - Returns the currently logged in user -*/ -export async function fetchCurrentUser(): Promise { - try { - const response = await api.get("/v1/auth/whoami") - return response.data - } catch (error) { - throw new Error("Failed to load user") - } -} diff --git a/frontend/src/api/users.ts b/frontend/src/api/users.ts new file mode 100644 index 00000000..bcfda7b2 --- /dev/null +++ b/frontend/src/api/users.ts @@ -0,0 +1,21 @@ +import api from "@/api" + +export interface User { + // Name + name: string; + + // Realname + realname?: string; +} + +/* + Returns the currently logged in user +*/ +export async function fetchCurrentUser(): Promise { + try { + const response = await api.get("/v1/auth/whoami") + return response.data + } catch (error) { + throw new Error("Failed to load user") + } +} diff --git a/frontend/src/composables/auth.ts b/frontend/src/composables/auth.ts index 9021be7f..f3d82cfa 100644 --- a/frontend/src/composables/auth.ts +++ b/frontend/src/composables/auth.ts @@ -1,7 +1,7 @@ import { computed } from "vue"; // Import types -import type { User } from "@/types/User"; +import type { User } from "@/api/users"; // Authentication Store import { useAuthStore } from "@/stores/auth"; diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index af7a1fdc..16ede5c4 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' -import type { User } from "@/types/User" -import { fetchCurrentUser } from "@/api/auth" +import type { User } from "@/api/users" +import { fetchCurrentUser } from "@/api/users" interface AuthState { user: User | null; diff --git a/frontend/src/types/User.ts b/frontend/src/types/User.ts deleted file mode 100644 index aafa4db5..00000000 --- a/frontend/src/types/User.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - Defines our User object -*/ -export interface User { - // Name - name: string; - - // Realname - realname?: string; -} -- 2.47.2