diff --git a/src/app/provider/authStore.ts b/src/app/provider/authStore.ts index 50033763..e29d17d1 100644 --- a/src/app/provider/authStore.ts +++ b/src/app/provider/authStore.ts @@ -1,15 +1,29 @@ import { create } from 'zustand'; +import { persist } from 'zustand/middleware'; interface AuthStore { + accessToken: string | null; + refreshToken: string | null; + setAccessToken: (token: string | null) => void; + setRefreshToken: (token: string | null) => void; + isModalOpen: boolean; openModal: () => void; closeModal: () => void; } -const useAuthStore = create(set => ({ - isModalOpen: false, - openModal: () => set({ isModalOpen: true }), - closeModal: () => set({ isModalOpen: false }), -})); +export const useAuthStore = create()( + persist( + (set) => ({ + accessToken: null, + refreshToken: null, + setAccessToken: (token) => set({ accessToken: token }), + setRefreshToken: (token) => set({ refreshToken: token }), + isModalOpen: false, + openModal: () => set({ isModalOpen: true }), + closeModal: () => set({ isModalOpen: false }), + }), { name: 'auth-storage' } + ) +); export default useAuthStore; diff --git a/src/pages/home/ui/MainPage.tsx b/src/pages/home/ui/MainPage.tsx index 0da29daf..9a8d5473 100644 --- a/src/pages/home/ui/MainPage.tsx +++ b/src/pages/home/ui/MainPage.tsx @@ -32,7 +32,7 @@ const MainPage = () => { const [closingStartIndex, setClosingStartIndex] = useState(0); const maxCardsToShow = 2; const navigate = useNavigate(); - const { isModalOpen, openModal, closeModal } = useAuthStore(); + const { isModalOpen, openModal, closeModal} = useAuthStore(); type SetStartIndex = Dispatch>; @@ -51,12 +51,12 @@ const MainPage = () => { } onClick={() => navigate('/search')} - onChange={() => {}} + onChange={() => { }} placeholder="입력해주세요" /> } leftButtonClassName="sm:text-lg md:text-xl lg:text-2xl font-extrabold font-nexon" - leftButtonClick={() => {}} + leftButtonClick={() => { }} leftButtonLabel="같이가요" rightContent={} /> @@ -91,6 +91,7 @@ const MainPage = () => { ) .map((event, index) => ( { ) .map((event, index) => ( { ) .map((event, index) => ( { const [isModalOpen, setIsModalOpen] = useState(false); const [myTickets, setMyTickets] = useState([]); const [selectedTicket, setSelectedTicket] = useState(null); - + const { setAccessToken, setRefreshToken } = useAuthStore(); + useEffect(() => { + const accessToken = Cookies.get('access-token'); + const refreshToken = Cookies.get('refresh-token'); + + console.log("access-token:", accessToken); + console.log("refresh-token:", refreshToken); + + if (accessToken) { + setAccessToken(accessToken); + } + if (refreshToken) { + setRefreshToken(refreshToken); + } + }, []); + useEffect(() => { const fetchMyTickets = async () => { try { diff --git a/src/shared/types/api/http-client.ts b/src/shared/types/api/http-client.ts index e4ad6860..6ac59cea 100644 --- a/src/shared/types/api/http-client.ts +++ b/src/shared/types/api/http-client.ts @@ -6,20 +6,21 @@ import useAuthStore from '../../../app/provider/authStore'; export const axiosClient = axios.create({ baseURL: 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/api/v1', timeout: 3000, + withCredentials: true, headers: { 'Content-Type': 'application/json', - Authorization: `Bearer ${import.meta.env.VITE_HEADER_TOKEN}`, + //Authorization: `Bearer `, }, }); axiosClient.interceptors.request.use( config => { - const token = Cookies.get('access_token'); + //const token = Cookies.get('access_token'); //zustand 사용함으로써 코드변경 할 듯 현재는 임시 입니다. - - if (token) { - config.headers.Authorization = `Bearer ${token}`; - } + // const token = useAuthStore.getState().accessToken; + // if (token) { + // config.headers.Authorization = `Bearer ${token}`; + // } return config; }, diff --git a/src/widgets/main/ui/LoginModal.tsx b/src/widgets/main/ui/LoginModal.tsx index 59353173..15514956 100644 --- a/src/widgets/main/ui/LoginModal.tsx +++ b/src/widgets/main/ui/LoginModal.tsx @@ -9,6 +9,12 @@ interface LoginModalProps { } const LoginModal = ({ onClose }: LoginModalProps) => { + const kakaoLogin = () => { + window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/kakao'; + }; + const gooleLogin = () => { + window.location.href = 'http://ec2-3-35-48-123.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/google'; + } return ( { } label="카카오 로그인" - onClick={() => {}} + onClick={kakaoLogin} className="mx-auto my-auto" /> @@ -38,7 +44,7 @@ const LoginModal = ({ onClose }: LoginModalProps) => { } label="Google 로그인" - onClick={() => {}} + onClick={gooleLogin} className="mx-auto my-auto" />