From d11e5e64f6aca28b3d0fc0ef02de527279eae682 Mon Sep 17 00:00:00 2001 From: al8763be Date: Sun, 17 Mar 2024 15:41:23 +0100 Subject: [PATCH 1/2] 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" }); } }, }; From 386f7c3a94f0ba7d53d668031576040dd7f63430 Mon Sep 17 00:00:00 2001 From: al8763be Date: Sun, 17 Mar 2024 15:49:34 +0100 Subject: [PATCH 2/2] API Login return { success: true, data: data.token } --- frontend/src/API/API.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index f1bef85..bd6518b 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -38,7 +38,7 @@ interface API { token: string, ): Promise>; /** Login */ - login(NewUser: NewUser): Promise>; + login(NewUser: NewUser): Promise>; } // Export an instance of the API @@ -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,8 +209,8 @@ export const api: API = { if (!response.ok) { return { success: false, message: "Failed to login" }; } else { - const data = (await response.json()) as JSON; - return { success: true, data }; + const data = (await response.json()) as { token: string }; // Update the type of 'data' + return { success: true, data: data.token }; } } catch (e) { return Promise.resolve({ success: false, message: "Failed to login" });