From d11e5e64f6aca28b3d0fc0ef02de527279eae682 Mon Sep 17 00:00:00 2001 From: al8763be Date: Sun, 17 Mar 2024 15:41:23 +0100 Subject: [PATCH] API Login return { success: true, data } data as JSON with token --- frontend/src/API/API.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index c1f237c..f1bef85 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -196,7 +196,7 @@ export const api: API = { } }, - async login(NewUser: NewUser): Promise> { + async login(NewUser: NewUser): Promise> { try { const response = await fetch("/api/login", { method: "POST", @@ -209,12 +209,11 @@ export const api: API = { if (!response.ok) { return { success: false, message: "Failed to login" }; } else { - const data = (await response.json()) as { token: string }; // Fix: Change the type of 'data' - const token = data.token; - return { success: true, data: token }; + const data = (await response.json()) as JSON; + return { success: true, data }; } } catch (e) { - return { success: false, message: "Failed to login" }; + return Promise.resolve({ success: false, message: "Failed to login" }); } }, };