API Login return { success: true, data } data as JSON with token
This commit is contained in:
parent
a28bab459a
commit
d11e5e64f6
1 changed files with 4 additions and 5 deletions
|
@ -196,7 +196,7 @@ export const api: API = {
|
|||
}
|
||||
},
|
||||
|
||||
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||
async login(NewUser: NewUser): Promise<APIResponse<JSON>> {
|
||||
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" });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue