TIL
Axios 사용법
yarn add axios
import axios from "axios";
- AUTH_API_HOST 상수를 정의하여 API 호스트 URL을 저장
const AUTH_API_HOST = "https://moneyfulpublicpolicy.co.kr";
export const register = async ({ id, password, nickname }) => {
try {
const response = await axios.post(AUTH_API_HOST + "/register", {
id: id,
password: password,
nickname: nickname,
});
return response.data;
} catch (error) {
console.log(error?.response?.data?.message);
alert(error?.response?.data?.message);
}
};
export const login = async ({ id, password }) => {
try {
const response = await axios.post(AUTH_API_HOST + "/login?expiresIn=10m",{
id: id,
password: password,
});
localStorage.setItem("accessToken, response.data.accessToken");
return response.data;
} catch (error) {
console.log(error?.response?.data?.message);
alert(error?.response?.data?.message);
}
};