From 386f7c3a94f0ba7d53d668031576040dd7f63430 Mon Sep 17 00:00:00 2001 From: al8763be Date: Sun, 17 Mar 2024 15:49:34 +0100 Subject: [PATCH] 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" });