API login returns { success: true, data: token }

This commit is contained in:
al8763be 2024-03-17 15:36:39 +01:00
parent 9511d509ca
commit a28bab459a

View file

@ -196,7 +196,7 @@ export const api: API = {
} }
}, },
async login(NewUser: NewUser): Promise<APIResponse<JSON>> { async login(NewUser: NewUser): Promise<APIResponse<string>> {
try { try {
const response = await fetch("/api/login", { const response = await fetch("/api/login", {
method: "POST", method: "POST",
@ -209,11 +209,12 @@ export const api: API = {
if (!response.ok) { if (!response.ok) {
return { success: false, message: "Failed to login" }; return { success: false, message: "Failed to login" };
} else { } else {
const data = (await response.json()) as JSON; const data = (await response.json()) as { token: string }; // Fix: Change the type of 'data'
return { success: true, data }; const token = data.token;
return { success: true, data: token };
} }
} catch (e) { } catch (e) {
return Promise.resolve({ success: false, message: "Failed to login" }); return { success: false, message: "Failed to login" };
} }
}, },
}; };