Skip to content

Commit 28c7062

Browse files
committed
fix: fix request header
1 parent c3d32ed commit 28c7062

9 files changed

+33
-29
lines changed

src/components/price/PriceItem.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function PriceItem(props) {
8888
} = props;
8989

9090
const [count, setCount] = useState(1);
91-
const user = useUser();
91+
const token = useUser();
9292

9393
const handleAddToCart = async () => {
9494
try {
@@ -98,7 +98,7 @@ function PriceItem(props) {
9898
method: "POST",
9999
headers: {
100100
"Content-Type": "application/json",
101-
Authorization: `Bearer ${user.token}`,
101+
Authorization: `Bearer ${token}`,
102102
},
103103
body: JSON.stringify({
104104
product_id: product_id,

src/components/shopping/ShoppingBudget.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function ShoppingBudget({ budget, present, hideButtons }) {
9999
const [isEditing, setIsEditing] = useState(false);
100100
const [newBudget, setNewBudget] = useState("");
101101
const state = budget - present;
102-
const user = useUser();
102+
const token = useUser();
103103

104104
const handleSetBudget = async () => {
105105
if (!newBudget || isNaN(newBudget)) {
@@ -114,7 +114,7 @@ function ShoppingBudget({ budget, present, hideButtons }) {
114114
method: "POST",
115115
headers: {
116116
"Content-Type": "application/json",
117-
Authorization: `Bearer ${user.token}`,
117+
Authorization: `Bearer ${token}`,
118118
},
119119
body: JSON.stringify({
120120
budget: parseInt(newBudget),
@@ -125,8 +125,6 @@ function ShoppingBudget({ budget, present, hideButtons }) {
125125
if (!response.ok) {
126126
throw new Error("예산 설정에 실패했습니다.");
127127
}
128-
129-
// API 호출 성공 후 페이지 새로고침
130128
window.location.reload();
131129
} catch (error) {
132130
console.error("예산 설정 실패:", error);

src/components/shopping/ShoppingList.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function ShoppingList({ hideButtons }) {
1717
const navigate = useNavigate();
1818
const [items, setItems] = useState([]);
1919
const [isLoading, setIsLoading] = useState(true);
20-
const user = useUser();
20+
const token = useUser();
2121

2222
useEffect(() => {
2323
const fetchShoppingList = async () => {
@@ -28,7 +28,7 @@ function ShoppingList({ hideButtons }) {
2828
method: "GET",
2929
headers: {
3030
"Content-Type": "application/json",
31-
Authorization: `Bearer ${user.token}`,
31+
Authorization: `Bearer ${token}`,
3232
},
3333
}
3434
);
@@ -47,7 +47,7 @@ function ShoppingList({ hideButtons }) {
4747
};
4848

4949
fetchShoppingList();
50-
}, [user.token]);
50+
}, [token]);
5151

5252
const handleDragEnd = (result) => {
5353
if (!result.destination) return;
@@ -71,7 +71,7 @@ function ShoppingList({ hideButtons }) {
7171
method: "POST",
7272
headers: {
7373
"Content-Type": "application/json",
74-
Authorization: `Bearer ${user.token}`,
74+
Authorization: `Bearer ${token}`,
7575
},
7676
credentials: "include",
7777
body: JSON.stringify({

src/pages/LandingPage.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const TrendContainer = styled.div`
104104
function LandingPage() {
105105
const [trendItems, setTrendItems] = useState([]);
106106
const navigate = useNavigate();
107-
const { user } = useUser();
107+
const { token, user } = useUser();
108108
const subtext =
109109
"계속 변동하는 물가에 맞게 생활하고 계신가요?\n합리적인 장바구니를 위해\nKU_PRICESNAP로 관리하세요.";
110110

@@ -116,7 +116,7 @@ function LandingPage() {
116116
method: "POST",
117117
headers: {
118118
"Content-Type": "application/json",
119-
Authorization: `Bearer ${user.token}`,
119+
Authorization: `Bearer ${token}`,
120120
},
121121
body: JSON.stringify({
122122
product_id: item.product_id,
@@ -151,7 +151,7 @@ function LandingPage() {
151151
method: "GET",
152152
headers: {
153153
"Content-Type": "application/json",
154-
Authorization: `Bearer ${user.token}`,
154+
Authorization: `Bearer ${token}`,
155155
},
156156
}
157157
);
@@ -163,7 +163,7 @@ function LandingPage() {
163163
};
164164

165165
fetchTrends();
166-
}, [user]);
166+
}, [user, token]);
167167

168168
return (
169169
<Container>

src/pages/MyPage.jsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const MyPageForm = styled.form`
2828

2929
function MyPage() {
3030
const [name, setName] = useState("");
31-
const { user, logout } = useUser();
31+
const { logout, token } = useUser();
3232
const navigate = useNavigate();
3333

3434
const handleSubmit = async (e) => {
@@ -41,18 +41,18 @@ function MyPage() {
4141
method: "PATCH",
4242
headers: {
4343
"Content-Type": "application/json",
44-
Authorization: `Bearer ${user.token}`,
44+
Authorization: `Bearer ${token}`,
4545
},
46-
body: JSON.stringify({ newName: name }),
46+
body: JSON.stringify({
47+
newName: name,
48+
}),
4749
}
4850
);
4951

5052
if (!response.ok) {
5153
const errorData = await response.json();
5254
throw new Error(errorData.message);
5355
}
54-
navigate("/");
55-
window.location.reload();
5656
console.log("닉네임 수정 성공");
5757
} catch (err) {
5858
console.log("닉네임 수정 실패");
@@ -70,7 +70,13 @@ function MyPage() {
7070
placeholder="닉네임을 입력해주세요"
7171
onChange={(e) => setName(e.target.value)}
7272
/>
73-
<Button title="프로필 수정 완료" className="brown" />
73+
<Button
74+
title="프로필 수정 완료"
75+
className="brown"
76+
onClick={() => {
77+
navigate("/");
78+
}}
79+
/>
7480
<Button
7581
title="로그아웃"
7682
onClick={() => {

src/pages/RegisterPage.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function RegisterPage() {
3131
const [name, setName] = useState("");
3232
const [password, setPassword] = useState("");
3333
const navigate = useNavigate();
34-
const user = useUser();
34+
const token = useUser();
3535

3636
const handleRegister = async (e) => {
3737
e.preventDefault();
@@ -43,7 +43,7 @@ function RegisterPage() {
4343
method: "POST",
4444
headers: {
4545
"Content-Type": "application/json",
46-
Authorization: `Bearer ${user.token}`,
46+
Authorization: `Bearer ${token}`,
4747
},
4848
body: JSON.stringify({
4949
userId: id,

src/pages/price/PriceCategorySearchPage.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const Text = styled.div`
6161
function PriceCategorySearchPage() {
6262
const [selectedCategoryId, setSelectedCategoryId] = useState(null);
6363
const [searchResults, setSearchResults] = useState([]);
64-
const user = useUser();
64+
const token = useUser();
6565

6666
const handleCategorySelect = (categoryId) => {
6767
setSelectedCategoryId(categoryId);
@@ -80,7 +80,7 @@ function PriceCategorySearchPage() {
8080
method: "GET",
8181
headers: {
8282
"Content-Type": "application/json",
83-
Authorization: `Bearer ${user.token}`,
83+
Authorization: `Bearer ${token}`,
8484
},
8585
}
8686
);

src/pages/price/PriceMainPage.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const Text = styled.div`
6161
function PriceMainPage() {
6262
const [price, setPrice] = useState([]);
6363
const navigate = useNavigate();
64-
const user = useUser();
64+
const { user, token } = useUser();
6565

6666
useEffect(() => {
6767
const fetchPrice = async () => {
@@ -77,7 +77,7 @@ function PriceMainPage() {
7777
method: "GET",
7878
headers: {
7979
"Content-Type": "application/json",
80-
Authorization: `Bearer ${user.token}`,
80+
Authorization: `Bearer ${token}`,
8181
},
8282
}
8383
);
@@ -90,7 +90,7 @@ function PriceMainPage() {
9090
};
9191

9292
fetchPrice();
93-
}, [user]);
93+
}, [user, token]);
9494

9595
return (
9696
<Container>

src/pages/price/PriceNameSearchPage.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Text = styled.div`
5959

6060
function PriceNameSearchPage() {
6161
const [searchResults, setSearchResults] = useState([]);
62-
const user = useUser();
62+
const token = useUser();
6363

6464
const handleSearch = async (name) => {
6565
try {
@@ -69,7 +69,7 @@ function PriceNameSearchPage() {
6969
method: "GET",
7070
headers: {
7171
"Content-Type": "application/json",
72-
Authorization: `Bearer ${user.token}`,
72+
Authorization: `Bearer ${token}`,
7373
},
7474
}
7575
);

0 commit comments

Comments
 (0)