From 0bb4c4e81cd4595828f4857ae1b06f9fc280f300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EB=AF=BC=EC=9E=AC?= Date: Tue, 5 Nov 2024 16:23:51 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Refact:=20api=20=EB=AA=A8=EB=93=88=ED=99=94?= =?UTF-8?q?=20=EC=9E=91=EC=97=85=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/Auth/dto.ts | 14 ++++++++++++++ src/apis/Auth/index.ts | 7 +++++++ src/apis/User/dto.ts | 15 --------------- .../Login/components/Kakao/KakaoCallback.tsx | 19 ++++++++++++++++--- 4 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 src/apis/Auth/dto.ts create mode 100644 src/apis/Auth/index.ts diff --git a/src/apis/Auth/dto.ts b/src/apis/Auth/dto.ts new file mode 100644 index 00000000..cedb7578 --- /dev/null +++ b/src/apis/Auth/dto.ts @@ -0,0 +1,14 @@ +// 네이버 로그인 +export type NaverLoginResponse = LoginResponse; + +// 카카오 로그인 +export type KakaoLoginResponse = LoginResponse; + +// 로그인 공통 응답 인터페이스 +export interface LoginResponse { + status: number; + data: { + message: string; + accessToken: string; + }; +} diff --git a/src/apis/Auth/index.ts b/src/apis/Auth/index.ts new file mode 100644 index 00000000..2249327d --- /dev/null +++ b/src/apis/Auth/index.ts @@ -0,0 +1,7 @@ +import { KakaoLoginResponse, NaverLoginResponse } from './dto'; +import { newRequest } from '../core'; + +export const getKakaoLoginApi = (code: string) => newRequest.get(`/auth/login/kakao?code=${code}`); + +export const getNaverLoginApi = (code: string) => + newRequest.get(`/auth/login/naver?code=${code}&state=STATE_TOKEN`); diff --git a/src/apis/User/dto.ts b/src/apis/User/dto.ts index 71540040..d2938009 100644 --- a/src/apis/User/dto.ts +++ b/src/apis/User/dto.ts @@ -1,11 +1,5 @@ import { BaseApiResponse } from '../util/dto'; -// 네이버 로그인 -export type NaverLoginResponse = LoginResponse; - -// 카카오 로그인 -export type KakaoLoginResponse = LoginResponse; - // 회원 탈퇴 export type DeleteUserResponse = BaseApiResponse; @@ -27,15 +21,6 @@ export type UpdateUserResponse = BaseApiResponse; export type CreateUserBlockRequest = BlockRequest; export type CreateUserBlockResponse = BaseApiResponse; -// 로그인 공통 응답 인터페이스 -export interface LoginResponse { - status: number; - data: { - message: string; - accessToken: string; - }; -} - // 회원 탈퇴 응답 데이터 export interface DeleteUserResult { message: string; diff --git a/src/pages/Login/components/Kakao/KakaoCallback.tsx b/src/pages/Login/components/Kakao/KakaoCallback.tsx index 1ed699bb..12e36534 100644 --- a/src/pages/Login/components/Kakao/KakaoCallback.tsx +++ b/src/pages/Login/components/Kakao/KakaoCallback.tsx @@ -1,11 +1,10 @@ -//카카오 인증 완료 후 인증 코드는 승인된 리디렉트 URL로 - import React, { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; import { GetUserInfoResult } from '../../../ProfileViewer/ResponseDto/GetUserInfoResult'; import request from '../../../../apis/core'; import Loading from '../../../../components/Loading'; +//import { getKakaoLoginApi } from '../../../../apis/Auth'; const KakaoCallback: React.FC = () => { const navigate = useNavigate(); @@ -15,6 +14,20 @@ const KakaoCallback: React.FC = () => { console.log(code); // 인증 코드 출력 if (code) { + // const getKakaoLogin = async () => { + // try{ + // const response = await getKakaoLoginApi(code); + // const statusCode = response.status; + // if (statusCode === 200) { + // const token = response.data.accessToken; + // localStorage.removeItem('jwt_token'); + // localStorage.setItem('NEW_JWT_TOKEN', token); + // } + // } + // catch (error) { + + // } + // } // 인증 코드를 쿼리스트링으로 백엔드 서버에 전송 axios .get(`https://api-dev.oodd.today/auth/login/kakao?code=${code}`) @@ -51,7 +64,7 @@ const KakaoCallback: React.FC = () => { console.error('로그인 실패:', response.data); alert('카카오 계정의 정보를 불러오지 못했습니다.'); navigate('/login'); - // 로그인 실패 시 처리 (예: 오류 페이지로 리디렉션) + // 로그인 실패 시 처리 } }) .catch((error) => { From aad5e1693ae41162e5579151167d97b03ec7a85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EB=AF=BC=EC=9E=AC?= Date: Tue, 5 Nov 2024 21:31:59 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20post=20=EB=9D=BC=EC=9A=B0=ED=8C=85?= =?UTF-8?q?=20=20=EA=B2=BD=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/components/PostItem/dto.ts | 1 + src/components/PostItem/index.tsx | 7 +++++-- src/pages/ProfileViewer/index.tsx | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/PostItem/dto.ts b/src/components/PostItem/dto.ts index f05b2121..69f42083 100644 --- a/src/components/PostItem/dto.ts +++ b/src/components/PostItem/dto.ts @@ -8,4 +8,5 @@ export interface Post { export interface PostItemProps { post: Post; + isMyPost: boolean; } diff --git a/src/components/PostItem/index.tsx b/src/components/PostItem/index.tsx index fd789b58..53704487 100644 --- a/src/components/PostItem/index.tsx +++ b/src/components/PostItem/index.tsx @@ -15,13 +15,16 @@ import MessageSvg from '../../assets/default/message.svg'; import PinIcon from '../../assets/default/pin.svg'; import { PostItemProps } from './dto'; -const PostItem: React.FC = ({ post }) => { +const PostItem: React.FC = ({ post, isMyPost }) => { const navigate = useNavigate(); const commentsCount = post.commentsCount ?? 0; // 현재 api 응답에 commentsCount가 없어 undefine 오류 해결 위해 설정, 추후 api 수정되면 삭제 해도 되는 행 const imageUrl = post.firstPhoto || 'https://via.placeholder.com/72'; + const handleClick = () => { - navigate(`/post/${post.postId}`); + const path = isMyPost ? `/my-post/${post.postId}` : `/post/${post.postId}`; + navigate(path); }; + return ( diff --git a/src/pages/ProfileViewer/index.tsx b/src/pages/ProfileViewer/index.tsx index 4e6a6b5d..af336cf9 100644 --- a/src/pages/ProfileViewer/index.tsx +++ b/src/pages/ProfileViewer/index.tsx @@ -208,8 +208,9 @@ const ProfileViewer: React.FC = () => { {representativePosts.length > 0 && - representativePosts.map((post) => )} - {otherPosts.length > 0 && otherPosts.map((post) => )} + representativePosts.map((post) => )} + {otherPosts.length > 0 && + otherPosts.map((post) => )} {activeBottomSheet === 'main' && ( Date: Tue, 5 Nov 2024 21:42:51 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20isMyPost=20default=20=EA=B0=92=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PostItem/dto.ts | 2 +- src/components/PostItem/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/PostItem/dto.ts b/src/components/PostItem/dto.ts index 69f42083..33976527 100644 --- a/src/components/PostItem/dto.ts +++ b/src/components/PostItem/dto.ts @@ -8,5 +8,5 @@ export interface Post { export interface PostItemProps { post: Post; - isMyPost: boolean; + isMyPost?: boolean; } diff --git a/src/components/PostItem/index.tsx b/src/components/PostItem/index.tsx index 53704487..4fd2593c 100644 --- a/src/components/PostItem/index.tsx +++ b/src/components/PostItem/index.tsx @@ -15,7 +15,7 @@ import MessageSvg from '../../assets/default/message.svg'; import PinIcon from '../../assets/default/pin.svg'; import { PostItemProps } from './dto'; -const PostItem: React.FC = ({ post, isMyPost }) => { +const PostItem: React.FC = ({ post, isMyPost = true }) => { const navigate = useNavigate(); const commentsCount = post.commentsCount ?? 0; // 현재 api 응답에 commentsCount가 없어 undefine 오류 해결 위해 설정, 추후 api 수정되면 삭제 해도 되는 행 const imageUrl = post.firstPhoto || 'https://via.placeholder.com/72';