장바구니 추가
const postCart = product => {
fetch('http://10.58.2.81:8000/carts/cart', {
method: 'POST',
headers: {
Authorization: localStorage.getItem('jwt'),
},
body: JSON.stringify({
product_id: product,
quantity: 1,
}),
})
.then(response => response.json())
.then(result => console.log('결과: ', result));
};
장바구니 불러오기
useEffect(() => {
fetch('http://10.58.2.81:8000/carts/cart', {
method: 'GET',
headers: { Authorization: localStorage.getItem('jwt') },
})
.then(response => response.json())
.then(data => setItems(data.carts));
}, []);
로그인후 토큰 로컬스테이지 저장
let login = () => {
fetch('http://10.58.6.107:8000/users/login', {
method: 'POST',
body: JSON.stringify({
email: id,
password: pw,
}),
})
.then(response => response.json())
.then(response => {
if (response.USER_NAME) {
localStorage.setItem('jwt', response.TOKEN);
navigate('/main-eokhwa');
}
});
};