committing summative

This commit is contained in:
Archie committed 2026-11-06 10:02:29 +00:00
1 parent 73ac8e85be
commit 95b138f29e
44 files changed
+5319 -755

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import { useCallback } from "react";
interface User {
id: string | null | undefined;
email: string | null | undefined;
name: string | null | undefined;
}
interface LoginCredentials {
email: string;
password: string;
}
interface RegisterCredentials extends LoginCredentials {
name?: string;
}
interface AuthResponse {
user: User;
message?: string;
error?: string;
}
export const register = async (credentials: RegisterCredentials): Promise<AuthResponse> => {
const response = await fetch("/api/auth/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(credentials), // turns credentials obj into json
credentials: "include"
});
const data: AuthResponse = await response.json(); // gets response data from promise and turns response into object
if (!response.ok) { // boolean value depending on success code
throw new Error(data.error || "Registration failed");
}
return data
}