login register

This commit is contained in:
2025-11-10 16:59:33 +07:00
parent 62f8299aef
commit 87269a6615
10 changed files with 249 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
const API_URL = "http://192.168.2.141:8080/api/auth";
export async function register(email: string, password: string) {
const response = await fetch(`${API_URL}/register`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
});
if (!response.ok) throw new Error("Đăng ký thất bại");
return await response.json();
}
export async function login(email: string, password: string) {
const response = await fetch(`${API_URL}/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
});
if (!response.ok) throw new Error("Đăng nhập thất bại");
return await response.json();
}
export async function logout(token: string) {
const response = await fetch(`${API_URL}/logout`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
});
return response.ok;
}