API Login return { success: true, data } data as JSON with token

This commit is contained in:
al8763be 2024-03-17 15:41:23 +01:00
parent a28bab459a
commit d11e5e64f6

View file

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