You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
677 B
28 lines
677 B
// src/api/api.js
|
|
import axios from 'axios';
|
|
|
|
const API_URL = 'http://localhost:8080/api/users';
|
|
|
|
export const registerUser = async (user) => {
|
|
try {
|
|
const response = await axios.post(`${API_URL}/register`, user);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(error.response?.data || 'Registration failed');
|
|
}
|
|
};
|
|
|
|
export const loginUser = async (loginAccount, password) => {
|
|
try {
|
|
const params = new URLSearchParams({
|
|
loginAccount,
|
|
password
|
|
});
|
|
|
|
const response = await axios.post(`${API_URL}/login`, params);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(error.response?.data || 'Login failed');
|
|
}
|
|
};
|