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 {
|
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" });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue