From e21fd8367cac3fa98642259e384dbc3ce34e0909 Mon Sep 17 00:00:00 2001 From: sonagi98 Date: Mon, 24 Jul 2023 17:46:16 +0900 Subject: [PATCH] =?UTF-8?q?fix/=20unthorization=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/MyPage/Bookmarks/MyBookmarks.tsx | 10 +++++++++- client/src/pages/MyPage/MyPage.tsx | 19 ++++++++++++++----- client/src/pages/MyPage/Reviews/MyReviews.tsx | 10 +++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/client/src/pages/MyPage/Bookmarks/MyBookmarks.tsx b/client/src/pages/MyPage/Bookmarks/MyBookmarks.tsx index f097cb5..6b46b28 100644 --- a/client/src/pages/MyPage/Bookmarks/MyBookmarks.tsx +++ b/client/src/pages/MyPage/Bookmarks/MyBookmarks.tsx @@ -1,18 +1,26 @@ import ShortMovieList from '../UI/ShortMovieList'; import { useEffect, useState } from 'react'; import axios from 'axios'; +import { getCookie } from '../../../utils/cookie'; interface MyBookmarkProps { id: number; } const MyBookmarks = ({ id }: MyBookmarkProps) => { + const token = getCookie('jwtToken'); const [bookmarks, setBookmark] = useState([]); useEffect(() => { const fetchBookmarks = async () => { try { const res = await axios.get( - `http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/${id}/bookmarks` + `http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/${id}/bookmarks`, + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + } ); if (res.status === 200) { const data = res.data; diff --git a/client/src/pages/MyPage/MyPage.tsx b/client/src/pages/MyPage/MyPage.tsx index 85c6182..f33e52e 100644 --- a/client/src/pages/MyPage/MyPage.tsx +++ b/client/src/pages/MyPage/MyPage.tsx @@ -5,14 +5,16 @@ import MyReviews from './Reviews/MyReviews'; import UserInfo from './UserInfo/UserInfo'; import DeleteUserBtn from './UI/deleteUserBtn'; import { User } from './assets/types/User'; +import { getCookie } from '../../utils/cookie'; const MyPage = () => { //TODO: hook으로 분리 - const [username, setName] = useState('name'); + const token = getCookie('jwtToken'); + // const [username, setName] = useState('name'); const [reviewCounter, setReviewCounter] = useState(0); const [user, setUser] = useState({ - username: username, + username: 'name', reviews: reviewCounter, memberId: 0, }); @@ -21,14 +23,21 @@ const MyPage = () => { const fetchInfo = async () => { try { const res = await axios.get( - 'http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/mypage' + 'http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/mypage', + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + } ); if (res.status === 200) { const data = res.data; - setName(data.username); + // console.log(data); + // setName(data.username); setUser({ - username: username, + username: data.username, reviews: 0, memberId: data.memberId, }); diff --git a/client/src/pages/MyPage/Reviews/MyReviews.tsx b/client/src/pages/MyPage/Reviews/MyReviews.tsx index 6d25f7c..fb023c8 100644 --- a/client/src/pages/MyPage/Reviews/MyReviews.tsx +++ b/client/src/pages/MyPage/Reviews/MyReviews.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import ShortMovieList from '../UI/ShortMovieList'; import axios from 'axios'; +import { getCookie } from '../../../utils/cookie'; // import { movies } from '../../UI/datalist'; interface MyReviewProps { @@ -10,12 +11,19 @@ interface MyReviewProps { const MyReviews = ({ reviewCounter, setReviewCount }: MyReviewProps) => { // TODO: 페이지네이션 컴포넌트 만들고 페이지네이션으로 변경 + const token = getCookie('jwtToken'); const [reviews, setReview] = useState([]); useEffect(() => { const fetchReviews = async () => { try { const res = await axios.get( - 'http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/reviews?page=1' + 'http://ec2-54-180-85-209.ap-northeast-2.compute.amazonaws.com:8080/members/reviews?page=1', + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + } ); if (res.status === 200) { const data = res.data;