diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 2769650..a30151c 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -33,6 +33,8 @@ interface API { username: string, token: string, ): Promise>; + /** Login */ + login(NewUser: NewUser): Promise>; } // Export an instance of the API @@ -156,7 +158,7 @@ export const api: API = { } }, - submitWeeklyReport: function ( + async submitWeeklyReport( project: NewWeeklyReport, token: string, ): Promise> { @@ -189,4 +191,25 @@ export const api: API = { }); } }, + + async login(NewUser: NewUser): Promise> { + try { + const response = await fetch("/api/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(NewUser), + }); + + if (!response.ok) { + return { success: false, message: "Failed to login" }; + } else { + const data = (await response.json()) as JSON; + return { success: true, data }; + } + } catch (e) { + return Promise.resolve({ success: false, message: "Failed to login" }); + } + }, };