login register
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user