diff --git a/src/App.js b/src/App.js index 64e7f73..3d3025d 100644 --- a/src/App.js +++ b/src/App.js @@ -27,11 +27,13 @@ export default function App() { //로그인 상태 관리하기-------------------------------- useEffect(() => { - // refreshTokenRequest(); - if (accessToken.accessToken !== null) { - history.push('/Waiting'); - } - }, []); + + //refreshTokenRequest() + if(accessToken.accessToken!==null){ + history.push('/Waiting') + } + },[]); + const loginHandler = (data) => { issueAccessToken(data.data.accessToken); history.push('/Waiting'); @@ -44,13 +46,11 @@ export default function App() { //로그 아웃-------------------------------------------------------- const hendleLogout = () => { axios - .get('http://localhost:4000/user/logout', { - headers: { - 'Content-Type': 'application/json', - 'Clear-Site-Data': 'cookies', - }, - }) - .then((res) => {}); + + .get( + 'http://localhost:4000/user/logout', + {withCredentials: true} + ).then((res) => {}) setUserInfo({ id: null, nickname: null, @@ -96,14 +96,16 @@ export default function App() { withCredentials: true, }) .then((res) => { - if (res.data.message !== 'ok') { - } - const { nickname, email, profile_image } = res.data.data.userInfo; - console.log(res.data.data.accessToken); - setAccessToken({ accessToken: res.data.data.accessToken }); + + if (res.data.message !== 'ok') {} + const { nickname, email, profile_image, id,comment } = res.data.data.userInfo; + console.log(res.data.data.accessToken) + setAccessToken({accessToken:res.data.data.accessToken}) setUserInfo({ + id : id, nickname: nickname, email: email, + comment:comment, profile_image: profile_image, }); }); diff --git a/src/MainPages/main.js b/src/MainPages/main.js index 8843fd1..f0ef645 100644 --- a/src/MainPages/main.js +++ b/src/MainPages/main.js @@ -23,7 +23,10 @@ export default function Main({ loginHandler, handleGuestLogin }) { const guestLogIn = () => { axios - .get('http://localhost:4000/guest') + .get('http://localhost:4000/guest', + { + withCredentials: true + }) .then((res) => { console.log(res.data); loginHandler(res.data); diff --git a/src/MyPages/MyPage.js b/src/MyPages/MyPage.js index 743a45b..af2503e 100644 --- a/src/MyPages/MyPage.js +++ b/src/MyPages/MyPage.js @@ -10,21 +10,37 @@ import Character2 from '../images/Character2.png'; import Character3 from '../images/Character3.png'; import Character4 from '../images/Character4.png'; -function MyPage({ accessToken, isLogIn, loginCheck, userInfo }) { +function MyPage({ accessToken, refreshTokenRequest, userInfo }) { const PhotoData = [Character1, Character2, Character3, Character4]; - const [isOpen, setIsOpen] = useState(false); const [isPhotoBoxOpen, setIsPhotoBoxOpen] = useState(false); const { nickname, email, profile_image, comment, id } = userInfo; - const defaultImageNum = profile_image === null ? 0 : profile_image; - const [nowPhoto, setPhoto] = useState(PhotoData[defaultImageNum]); + const [PhotoNum, setPhotoNum] = useState(0); + const [nowPhoto, setPhoto] = useState(PhotoData[profile_image]); + const [text, setText] = useState(null); + + // const emailInputValue = (e) => { + // setEmail(e.target.value); + // }; + + // const passwordInputValue = (e) => { + // setPassword(e.target.value); + // }; + + // const nickNameInputValue = (e) => { + // setNickName(e.target.value); + // }; + const ChangeInputPhoto = function (photo) { // e.preventDefault(); setPhoto(photo); + setPhotoNum(PhotoData.indexOf(nowPhoto)) + console.log(PhotoNum) if (photo !== nowPhoto) { console.log('openModal'); openModal(); } + //MyPageSaveData() }; const openModal = () => { setIsOpen(true); @@ -41,31 +57,35 @@ function MyPage({ accessToken, isLogIn, loginCheck, userInfo }) { } }; - const MyPageSaveData = async () => { - const PhotoNum = PhotoData.findIndex(nowPhoto); - const SavePhoto = await axios.post( - `http://localhost:4000/mypage/${id}/profile`, - { - authorization: accessToken, - new_profile: PhotoNum, + + const MyPageSaveData= async (PhotoNum) =>{ + + await refreshTokenRequest() + const SavePhoto = await axios.post(`http://localhost:4000/mypage/${id}/profile`, + {new_profile: PhotoNum}, + { + headers: { + Authorization: `Bearer ${accessToken.accessToken}`, + 'Content-Type': 'application/json', }, - { - headers: { 'Content-Type': 'application/json' }, - Credentials: 'include', - } - ); - const SaveComment = await axios.post( - `http://localhost:4000/mypage/${id}/comment`, - { - authorization: accessToken, - Comment: PhotoNum, - } - ); - }; + //withCredentials: true, + }) + const SaveComment = await axios.post(`http://localhost:4000/mypage/${id}/comment`, + {Comment: '아니라어민어리ㅏㅁㄴ얼'}, + { + headers: { + Authorization: `Bearer ${accessToken.accessToken}`, + 'Content-Type': 'application/json', + }, + //withCredentials: true, + }) + } + + return (