Skip to content

Commit c5b62a0

Browse files
committed
fix: fix shoppinglist
1 parent dac9aec commit c5b62a0

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/components/shopping/ShoppingList.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const ListContainer = styled.div`
1515

1616
function ShoppingList({ hideButtons }) {
1717
const navigate = useNavigate();
18+
const { token } = useUser();
1819
const [items, setItems] = useState([]);
1920
const [isLoading, setIsLoading] = useState(true);
20-
const token = useUser();
2121

2222
useEffect(() => {
2323
const fetchShoppingList = async () => {
@@ -30,6 +30,7 @@ function ShoppingList({ hideButtons }) {
3030
"Content-Type": "application/json",
3131
Authorization: `Bearer ${token}`,
3232
},
33+
credentials: "include",
3334
}
3435
);
3536

@@ -46,7 +47,9 @@ function ShoppingList({ hideButtons }) {
4647
}
4748
};
4849

49-
fetchShoppingList();
50+
if (token) {
51+
fetchShoppingList();
52+
}
5053
}, [token]);
5154

5255
const handleDragEnd = (result) => {
@@ -90,7 +93,7 @@ function ShoppingList({ hideButtons }) {
9093
alert("장바구니가 저장되었습니다.");
9194
} catch (error) {
9295
console.error("저장 실패:", error);
93-
alert("저장에 실패했습니다. 다시 시도해주세요.");
96+
alert("저장에 실패했습니다. 다시 시도해주��요.");
9497
}
9598
};
9699

src/pages/MyPage.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const MyPageForm = styled.form`
2727
`;
2828

2929
function MyPage() {
30-
const { logout, token, user, setUser } = useUser();
30+
const { logout, token, user } = useUser();
3131
const navigate = useNavigate();
3232
const [name, setName] = useState(user?.name || "");
3333

@@ -52,10 +52,9 @@ function MyPage() {
5252
if (response.ok) {
5353
const updatedUser = { ...user, name: name };
5454
localStorage.setItem("user", JSON.stringify(updatedUser));
55-
setUser(updatedUser);
5655

5756
alert("닉네임이 성공적으로 변경되었습니다.");
58-
navigate("/");
57+
window.location.href = "/";
5958
} else {
6059
const errorData = await response.json();
6160
throw new Error(errorData.message);

0 commit comments

Comments
 (0)