diff --git a/src/Router.js b/src/Router.js index 7be4fec..b2cd353 100644 --- a/src/Router.js +++ b/src/Router.js @@ -17,6 +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 SocialLoginCallback from "./pages/SocialLoginCallback"; const AppRouter = () => { return ( @@ -40,6 +41,7 @@ const AppRouter = () => { } /> } /> } /> + } /> ); }; diff --git a/src/components/common/MypageSubMenu.jsx b/src/components/common/MypageSubMenu.jsx index 8d7e6a3..a99dad4 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 React, { useState, useEffect, useMemo } from "react"; +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: }, @@ -34,17 +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 if (!activeItem && activeMenu !== menuItems[0].name) { + setActiveMenu(menuItems[0].name); + navigate(menuItems[0].path, { replace: true }); } - }, [location.pathname, menuItems]); + }, [location.pathname, userType, menuItems, activeMenu, navigate]); // 메뉴 항목 클릭 시 activeMenu 상태 업데이트 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 ? ( 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/SignUpModal.jsx b/src/pages/SignUpModal.jsx index 39b3b34..2db2c5c 100644 --- a/src/pages/SignUpModal.jsx +++ b/src/pages/SignUpModal.jsx @@ -18,31 +18,35 @@ function SignUpModal({ onClose }) { onClose(); }; + const handleSocialSignUp = (provider) => { + window.location.href = `https://www.danpat.store/oauth2/authorization/${provider}`; + }; + return ( - handleSignUp('worker')}> + 개인 회원 원하는 시간, 딱 맞는 알바,지금 시작해보세요! - + handleSignUp('worker')}> 개인회원 가입하기 - - - 네이버 - - - - - 카카오톡 - + handleSocialSignUp("naver")}> + + 네이버 + + + handleSocialSignUp("kakao")}> + + 카카오톡 + handleSignUp('owner')}> diff --git a/src/pages/SocialLoginCallback.jsx b/src/pages/SocialLoginCallback.jsx new file mode 100644 index 0000000..b65f378 --- /dev/null +++ b/src/pages/SocialLoginCallback.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 SocialLoginCallback = () => { + const navigate = useNavigate(); + const { updateUser } = useUserInfo(); + + useEffect(() => { + const handleSocialLogin = async () => { + // 현재 URL에서 code 값 가져오기 + const urlParams = new URLSearchParams(window.location.search); + const code = urlParams.get("accessToken"); + + if (!code) { + alert("로그인 코드가 없습니다."); + navigate("/login"); + return; + } + + try { + // 백엔드 API에 GET 요청 보내기 + const response = await request.get(`/oauth2/login?token=${code}`); + + // 받은 데이터에서 필요한 값 추출 + const { accessToken, userId, userRole, name, profile, email } = response; + + // 사용자 정보 업데이트 + 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 SocialLoginCallback;
원하는 시간, 딱 맞는 알바,지금 시작해보세요!
개인회원 가입하기