From 7ba98fcaa581d42a5c70053daf0a340bf631e281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Wed, 2 Apr 2025 19:04:46 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=EC=86=8C=EC=85=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Router.js | 4 ++ src/pages/LoginModal.jsx | 8 +++- src/pages/SocialLoginCallbackKakao.jsx | 51 ++++++++++++++++++++++++++ src/pages/SocialLoginCallbackNaver.jsx | 51 ++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/pages/SocialLoginCallbackKakao.jsx create mode 100644 src/pages/SocialLoginCallbackNaver.jsx diff --git a/src/Router.js b/src/Router.js index 7be4fec..6d51556 100644 --- a/src/Router.js +++ b/src/Router.js @@ -17,6 +17,8 @@ import SavedWorkers from './pages/MyPage/SavedWorkers'; import AlbaReviewPage from './pages/AlbaReviewPage'; import MyResume from './pages/MyResume/MyResume'; import MyStoreForm from './pages/MyPage/MyStore/MyStoreForm'; +import SocialLoginCallbackNaver from "./pages/SocialLoginCallbackNaver"; +import SocialLoginCallbackKakao from "./pages/SocialLoginCallbackKakao"; const AppRouter = () => { return ( @@ -40,6 +42,8 @@ const AppRouter = () => { } /> } /> } /> + } /> + } /> ); }; diff --git a/src/pages/LoginModal.jsx b/src/pages/LoginModal.jsx index ae9dca6..a32318f 100644 --- a/src/pages/LoginModal.jsx +++ b/src/pages/LoginModal.jsx @@ -46,6 +46,10 @@ function LoginModal({ onClose }) { } }; + const handleSocialLogin = (provider) => { + window.location.href = `https://www.danpat.store/oauth2/authorization/${provider}`; + }; + return ( @@ -100,8 +104,8 @@ function LoginModal({ onClose }) {
- - + handleSocialLogin("naver")} /> + handleSocialLogin("kakao")} />
)} diff --git a/src/pages/SocialLoginCallbackKakao.jsx b/src/pages/SocialLoginCallbackKakao.jsx new file mode 100644 index 0000000..62dcf1b --- /dev/null +++ b/src/pages/SocialLoginCallbackKakao.jsx @@ -0,0 +1,51 @@ +import { useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import { useUserInfo } from '../contexts/useUserInfo.js'; +import request from "../api/request.ts"; + +const SocialLoginCallbackKakao = () => { + const navigate = useNavigate(); + const { updateUser } = useUserInfo(); + + useEffect(() => { + const handleSocialLogin = async () => { + // 현재 URL에서 code 값 가져오기 + const urlParams = new URLSearchParams(window.location.search); + const code = urlParams.get("code"); + + if (!code) { + alert("로그인 코드가 없습니다."); + navigate("/login"); + return; + } + + try { + // 백엔드 API에 GET 요청 보내기 + const response = await request.get(`/oauth2/callback/kakao?code=${code}`); + + // 받은 데이터에서 필요한 값 추출 + const { accessToken, userId, userRole, name, profile, email } = response.data; + + // 사용자 정보 업데이트 + updateUser({ id: userId, role: userRole, name: name, profileImage: profile, email: email }); + + + // Axios 헤더 업데이트 + request.updateToken(accessToken); + + // 로그인 성공하면 홈으로 이동 + navigate("/"); + } catch (error) { + console.error("소셜 로그인 처리 중 오류 발생:", error); + alert("로그인 중 오류가 발생했습니다."); + navigate("/login"); + } + }; + + handleSocialLogin(); + }, [navigate]); + + return
카카오 로그인 중입니다...
; +}; + +export default SocialLoginCallbackKakao; diff --git a/src/pages/SocialLoginCallbackNaver.jsx b/src/pages/SocialLoginCallbackNaver.jsx new file mode 100644 index 0000000..9d107c2 --- /dev/null +++ b/src/pages/SocialLoginCallbackNaver.jsx @@ -0,0 +1,51 @@ +import { useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import { useUserInfo } from '../contexts/useUserInfo.js'; +import request from "../api/request.ts"; + +const SocialLoginCallbackKakao = () => { + const navigate = useNavigate(); + const { updateUser } = useUserInfo(); + + useEffect(() => { + const handleSocialLogin = async () => { + // 현재 URL에서 code 값 가져오기 + const urlParams = new URLSearchParams(window.location.search); + const code = urlParams.get("code"); + + if (!code) { + alert("로그인 코드가 없습니다."); + navigate("/login"); + return; + } + + try { + // 백엔드 API에 GET 요청 보내기 + const response = await request.get(`/oauth2/callback/naver?code=${code}`); + + // 받은 데이터에서 필요한 값 추출 + const { accessToken, userId, userRole, name, profile, email } = response.data; + + // 사용자 정보 업데이트 + updateUser({ id: userId, role: userRole, name: name, profileImage: profile, email: email }); + + + // Axios 헤더 업데이트 + request.updateToken(accessToken); + + // 로그인 성공하면 홈으로 이동 + navigate("/"); + } catch (error) { + console.error("소셜 로그인 처리 중 오류 발생:", error); + alert("로그인 중 오류가 발생했습니다."); + navigate("/login"); + } + }; + + handleSocialLogin(); + }, [navigate]); + + return
네이버 로그인 중입니다...
; +}; + +export default SocialLoginCallbackKakao; From 24c32e7f2932069bcb438ffc96345ea7bb90b4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Wed, 2 Apr 2025 21:48:07 +0900 Subject: [PATCH 2/8] =?UTF-8?q?modify:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=84=9C=EB=B8=8C=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=EA=B0=92=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/MypageSubMenu.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/common/MypageSubMenu.jsx b/src/components/common/MypageSubMenu.jsx index 8d7e6a3..9b2923d 100644 --- a/src/components/common/MypageSubMenu.jsx +++ b/src/components/common/MypageSubMenu.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { useLocation } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; import { Link } from "react-router-dom"; import styled from "styled-components"; @@ -12,8 +12,11 @@ import { BsBookmarkFill } from "react-icons/bs"; const MypageSubMenu = ({ userType }) => { const location = useLocation(); // 현재 경로 가져오기 + const navigate = useNavigate(); const [activeMenu, setActiveMenu] = useState(null); + + // 알바생과 사장님의 공통 메뉴 항목 const commonMenu = [ { name: '체결 현황', path: '/mypage/contracts', icon: }, @@ -43,8 +46,12 @@ const MypageSubMenu = ({ userType }) => { const activeItem = menuItems.find((item) => item.path === currentPath); if (activeItem) { setActiveMenu(activeItem.name); + } else { + const defaultMenu = menuItems[0]; // 첫 번째 메뉴를 기본값으로 + setActiveMenu(defaultMenu.name); + navigate(defaultMenu.path, { replace: true }); } - }, [location.pathname, menuItems]); + }, [location.pathname, menuItems, navigate]); // 메뉴 항목 클릭 시 activeMenu 상태 업데이트 From 4b677d76b7ea5f9626a61b0525e9a5308cbfb12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Wed, 2 Apr 2025 22:00:09 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=EB=A7=8C=20=EB=A7=88?= =?UTF-8?q?=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=91=EA=B7=BC=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/Header.jsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/layout/Header.jsx b/src/components/layout/Header.jsx index d423eab..2b19f96 100644 --- a/src/components/layout/Header.jsx +++ b/src/components/layout/Header.jsx @@ -60,7 +60,17 @@ function Header() { 알바찾기 알바후기 고객지원 - 마이페이지 + { + if (!isAuthenticated) { + e.preventDefault(); // ✅ 기본 이동 동작 막기 + alert("로그인 후 이용해주세요."); + } + }} + > + 마이페이지 + {isAuthenticated ? ( From 56ff7b45bbb433ac69122782a326abe1c019c376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Wed, 2 Apr 2025 22:00:45 +0900 Subject: [PATCH 4/8] =?UTF-8?q?modify:=20=EC=98=A4=EB=A5=98=20=EC=8B=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99=EA=B2=BD=EB=A1=9C=20=ED=99=88=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/SocialLoginCallbackKakao.jsx | 2 +- src/pages/SocialLoginCallbackNaver.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/SocialLoginCallbackKakao.jsx b/src/pages/SocialLoginCallbackKakao.jsx index 62dcf1b..1e93195 100644 --- a/src/pages/SocialLoginCallbackKakao.jsx +++ b/src/pages/SocialLoginCallbackKakao.jsx @@ -38,7 +38,7 @@ const SocialLoginCallbackKakao = () => { } catch (error) { console.error("소셜 로그인 처리 중 오류 발생:", error); alert("로그인 중 오류가 발생했습니다."); - navigate("/login"); + navigate("/"); } }; diff --git a/src/pages/SocialLoginCallbackNaver.jsx b/src/pages/SocialLoginCallbackNaver.jsx index 9d107c2..126ddbf 100644 --- a/src/pages/SocialLoginCallbackNaver.jsx +++ b/src/pages/SocialLoginCallbackNaver.jsx @@ -38,7 +38,7 @@ const SocialLoginCallbackKakao = () => { } catch (error) { console.error("소셜 로그인 처리 중 오류 발생:", error); alert("로그인 중 오류가 발생했습니다."); - navigate("/login"); + navigate("/"); } }; From 8337cd49e30c5d54e89a8007a2a9d3d63cd3908b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Thu, 3 Apr 2025 23:28:16 +0900 Subject: [PATCH 5/8] =?UTF-8?q?modify:=20=EC=86=8C=EC=85=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=9A=94=EC=B2=AD=20=EA=B2=BD=EB=A1=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 --- src/Router.js | 6 +-- ...lbackKakao.jsx => SocialLoginCallback.jsx} | 10 ++-- src/pages/SocialLoginCallbackNaver.jsx | 51 ------------------- 3 files changed, 7 insertions(+), 60 deletions(-) rename src/pages/{SocialLoginCallbackKakao.jsx => SocialLoginCallback.jsx} (85%) delete mode 100644 src/pages/SocialLoginCallbackNaver.jsx diff --git a/src/Router.js b/src/Router.js index 6d51556..b2cd353 100644 --- a/src/Router.js +++ b/src/Router.js @@ -17,8 +17,7 @@ import SavedWorkers from './pages/MyPage/SavedWorkers'; import AlbaReviewPage from './pages/AlbaReviewPage'; import MyResume from './pages/MyResume/MyResume'; import MyStoreForm from './pages/MyPage/MyStore/MyStoreForm'; -import SocialLoginCallbackNaver from "./pages/SocialLoginCallbackNaver"; -import SocialLoginCallbackKakao from "./pages/SocialLoginCallbackKakao"; +import SocialLoginCallback from "./pages/SocialLoginCallback"; const AppRouter = () => { return ( @@ -42,8 +41,7 @@ const AppRouter = () => { } /> } /> } /> - } /> - } /> + } /> ); }; diff --git a/src/pages/SocialLoginCallbackKakao.jsx b/src/pages/SocialLoginCallback.jsx similarity index 85% rename from src/pages/SocialLoginCallbackKakao.jsx rename to src/pages/SocialLoginCallback.jsx index 1e93195..b65f378 100644 --- a/src/pages/SocialLoginCallbackKakao.jsx +++ b/src/pages/SocialLoginCallback.jsx @@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom"; import { useUserInfo } from '../contexts/useUserInfo.js'; import request from "../api/request.ts"; -const SocialLoginCallbackKakao = () => { +const SocialLoginCallback = () => { const navigate = useNavigate(); const { updateUser } = useUserInfo(); @@ -11,7 +11,7 @@ const SocialLoginCallbackKakao = () => { const handleSocialLogin = async () => { // 현재 URL에서 code 값 가져오기 const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get("code"); + const code = urlParams.get("accessToken"); if (!code) { alert("로그인 코드가 없습니다."); @@ -21,10 +21,10 @@ const SocialLoginCallbackKakao = () => { try { // 백엔드 API에 GET 요청 보내기 - const response = await request.get(`/oauth2/callback/kakao?code=${code}`); + const response = await request.get(`/oauth2/login?token=${code}`); // 받은 데이터에서 필요한 값 추출 - const { accessToken, userId, userRole, name, profile, email } = response.data; + const { accessToken, userId, userRole, name, profile, email } = response; // 사용자 정보 업데이트 updateUser({ id: userId, role: userRole, name: name, profileImage: profile, email: email }); @@ -48,4 +48,4 @@ const SocialLoginCallbackKakao = () => { return
카카오 로그인 중입니다...
; }; -export default SocialLoginCallbackKakao; +export default SocialLoginCallback; diff --git a/src/pages/SocialLoginCallbackNaver.jsx b/src/pages/SocialLoginCallbackNaver.jsx deleted file mode 100644 index 126ddbf..0000000 --- a/src/pages/SocialLoginCallbackNaver.jsx +++ /dev/null @@ -1,51 +0,0 @@ -import { useEffect } from "react"; -import { useNavigate } from "react-router-dom"; -import { useUserInfo } from '../contexts/useUserInfo.js'; -import request from "../api/request.ts"; - -const SocialLoginCallbackKakao = () => { - const navigate = useNavigate(); - const { updateUser } = useUserInfo(); - - useEffect(() => { - const handleSocialLogin = async () => { - // 현재 URL에서 code 값 가져오기 - const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get("code"); - - if (!code) { - alert("로그인 코드가 없습니다."); - navigate("/login"); - return; - } - - try { - // 백엔드 API에 GET 요청 보내기 - const response = await request.get(`/oauth2/callback/naver?code=${code}`); - - // 받은 데이터에서 필요한 값 추출 - const { accessToken, userId, userRole, name, profile, email } = response.data; - - // 사용자 정보 업데이트 - updateUser({ id: userId, role: userRole, name: name, profileImage: profile, email: email }); - - - // Axios 헤더 업데이트 - request.updateToken(accessToken); - - // 로그인 성공하면 홈으로 이동 - navigate("/"); - } catch (error) { - console.error("소셜 로그인 처리 중 오류 발생:", error); - alert("로그인 중 오류가 발생했습니다."); - navigate("/"); - } - }; - - handleSocialLogin(); - }, [navigate]); - - return
네이버 로그인 중입니다...
; -}; - -export default SocialLoginCallbackKakao; From abcc8ff4a0fbeea78c22d72c4d509a8f8d81b7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Fri, 4 Apr 2025 00:32:52 +0900 Subject: [PATCH 6/8] =?UTF-8?q?modify:=20=EB=AC=B4=ED=95=9C=EB=A3=A8?= =?UTF-8?q?=ED=94=84=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/MypageSubMenu.jsx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/common/MypageSubMenu.jsx b/src/components/common/MypageSubMenu.jsx index 9b2923d..a99dad4 100644 --- a/src/components/common/MypageSubMenu.jsx +++ b/src/components/common/MypageSubMenu.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useMemo } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import { Link } from "react-router-dom"; import styled from "styled-components"; @@ -37,21 +37,24 @@ const MypageSubMenu = ({ userType }) => { ...commonMenu ]; - // 사용자 타입에 맞는 메뉴 선택 - const menuItems = userType === 'worker' ? workerMenu : ownerMenu; - - // 초기 activeMenu를 현재 경로로 설정 + const menuItems = useMemo(() => { + if (!userType) return []; + return userType === "worker" ? workerMenu : ownerMenu; + }, [userType]); + useEffect(() => { + if (!userType || menuItems.length === 0) return; + const currentPath = location.pathname; const activeItem = menuItems.find((item) => item.path === currentPath); - if (activeItem) { + + if (activeItem && activeMenu !== activeItem.name) { setActiveMenu(activeItem.name); - } else { - const defaultMenu = menuItems[0]; // 첫 번째 메뉴를 기본값으로 - setActiveMenu(defaultMenu.name); - navigate(defaultMenu.path, { replace: true }); + } else if (!activeItem && activeMenu !== menuItems[0].name) { + setActiveMenu(menuItems[0].name); + navigate(menuItems[0].path, { replace: true }); } - }, [location.pathname, menuItems, navigate]); + }, [location.pathname, userType, menuItems, activeMenu, navigate]); // 메뉴 항목 클릭 시 activeMenu 상태 업데이트 From 05212b2be5863c2c4374af824d3b05f118a77d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Fri, 4 Apr 2025 00:39:21 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=B2=84=ED=8A=BC=EC=97=90=EB=8F=84=20=EC=86=8C?= =?UTF-8?q?=EC=85=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B2=BD=EB=A1=9C=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/SignUpModal.jsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pages/SignUpModal.jsx b/src/pages/SignUpModal.jsx index 39b3b34..fb02398 100644 --- a/src/pages/SignUpModal.jsx +++ b/src/pages/SignUpModal.jsx @@ -18,6 +18,10 @@ function SignUpModal({ onClose }) { onClose(); }; + const handleSocialSignUp = (provider) => { + window.location.href = `https://www.danpat.store/oauth2/authorization/${provider}`; + }; + return ( @@ -34,15 +38,15 @@ function SignUpModal({ onClose }) {
- - - 네이버 - -
- - - 카카오톡 - + handleSocialSignUp("naver")}> + + 네이버 + +
+ handleSocialSignUp("kakao")}> + + 카카오톡 +
handleSignUp('owner')}> From 6cb181d1a354fd519b40e2b94e599e68fa81229f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=95=84=EC=98=81?= Date: Fri, 4 Apr 2025 00:41:30 +0900 Subject: [PATCH 8/8] =?UTF-8?q?modify:=20=EC=9D=BC=EB=B0=98=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=ED=81=B4=EB=A6=AD=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/SignUpModal.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/SignUpModal.jsx b/src/pages/SignUpModal.jsx index fb02398..2db2c5c 100644 --- a/src/pages/SignUpModal.jsx +++ b/src/pages/SignUpModal.jsx @@ -25,14 +25,14 @@ function SignUpModal({ onClose }) { return ( - handleSignUp('worker')}> +
worker 개인 회원

원하는 시간, 딱 맞는 알바,
지금 시작해보세요!

-