Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 1x 1x 2x 2x 2x 1x 1x | import { AUTH_ENDPOINT } from "./endpoints";
/**
* Function to log in a user
* TODO: Wrap this in a try-catch block to match other api functions
* @param {string} firstName - The first name of the user
* @param {string} lastName - The last name of the user
* @param {string} email - The email of the user
* @param {string} password - The password of the user
* @returns {Promise<{ data?: any; error?: string }>} - The response from the server or an error message
* @throws {Error} - Throws an error if the request fails
*/
export async function registerUser(firstName: string, lastName: string, email: string, password: string) {
const response = await fetch(`${AUTH_ENDPOINT}/signup`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
password,
first_name: firstName,
last_name: lastName
}),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Failed to register user");
}
return data;
} |