From da38c111365562d72adb45e44f952ac49760b7eb Mon Sep 17 00:00:00 2001 From: kimhyerims Date: Wed, 25 Dec 2024 12:14:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#122=20[FEAT]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/login.js | 9 +++++++++ src/axios/index.js | 12 ++++++++++-- src/pages/LoginPage/LoginPage.jsx | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/apis/login.js diff --git a/src/apis/login.js b/src/apis/login.js new file mode 100644 index 0000000..9255bd1 --- /dev/null +++ b/src/apis/login.js @@ -0,0 +1,9 @@ +import { authAxios, testAxios } from '../axios'; + +// 로그인 +export const kakaoLoginAPI = async () => { + const response = await testAxios.get(`/login`); + // const loginUrl = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=856122255feeea21d537c0225f6c658a&redirect_uri=http://localhost:8080/auth/kakao/callback`; + const loginUrl = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=856122255feeea21d537c0225f6c658a&redirect_uri=https://wellet.store/auth/kakao/callback`; + window.location.href = loginUrl; +}; diff --git a/src/axios/index.js b/src/axios/index.js index 41a04e7..ee4f196 100644 --- a/src/axios/index.js +++ b/src/axios/index.js @@ -10,6 +10,15 @@ export const authAxios = axios.create({ }, }); +export const testAxios = axios.create({ + // baseURL: "http://localhost:8080", + baseURL: 'https://wellet.store', + withCredentials: true, + headers: { + 'Content-Type': 'application/json', + }, +}); + const getTokenFromCookie = () => { // const cookie = document.cookie // .split('; ') @@ -18,8 +27,7 @@ const getTokenFromCookie = () => { return dummyToken; }; -const dummyToken = - 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzODQ1Njk3MjEwIiwicm9sZSI6IlVTRVIiLCJuaWNrbmFtZSI6Iuq5gO2YnOumvCIsImlkIjozODQ1Njk3MjEwLCJleHAiOjE3MzQ4Nzk5ODIsImlhdCI6MTczNDg3NjM4MiwidXNlcm5hbWUiOiIwMTVmZDUwNy0zNWJiLTQxNmYtYjQ4OC03Y2JiN2NjYTQ0NjQifQ.Glv2-tcXLiqhI3TasBvC9WmS9P7YE7-AC1RnS9gzl_x0hfBxW5jfcTvsqBS7D6o40rbBKUPU8Iscvs1PsDiB2g'; +const dummyToken = '토큰값'; // 요청을 보낼 때 Bearer Token을 Authorization 헤더에 추가합니다. authAxios.interceptors.request.use( (config) => { diff --git a/src/pages/LoginPage/LoginPage.jsx b/src/pages/LoginPage/LoginPage.jsx index b9b45aa..c8dd1be 100644 --- a/src/pages/LoginPage/LoginPage.jsx +++ b/src/pages/LoginPage/LoginPage.jsx @@ -5,9 +5,21 @@ import login_background_lines from '../../assets/images/login_background_lines.s import { PrimaryButton, SecondaryButton } from '../../components'; import { useNavigate } from 'react-router-dom'; +// import { kakaoLoginAPI, getUserInfo } from '../../apis/login'; +import { kakaoLoginAPI } from '../../apis/login'; + export default function LoginPage() { const navigate = useNavigate(); + async function kakaoLogin() { + try { + const response = await kakaoLoginAPI(); // 카카오 로그인 API 호출 + } catch (error) { + // 로그인 실패 시 처리 + alert('로그인 실패. 다시 시도.' + error); + } + } + return ( navigate('/home')} + // onClick={() => navigate('/home')} + // onClick={() => kakaoLogin } + onClick={kakaoLogin} > From f1ff1b0e4f6998a69824a155d2555467e952b0c2 Mon Sep 17 00:00:00 2001 From: kimhyerims Date: Wed, 25 Dec 2024 12:26:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#122=20[FEAT]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/index.js | 1 + src/pages/LoginPage/LoginPage.jsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apis/index.js b/src/apis/index.js index 44b8004..bb1e2dc 100644 --- a/src/apis/index.js +++ b/src/apis/index.js @@ -8,3 +8,4 @@ export { searchCards, } from './cards'; export { getMyCard, postMyCard, deleteMyCard, putMyCard } from './myCard'; +export { kakaoLoginAPI } from './login'; diff --git a/src/pages/LoginPage/LoginPage.jsx b/src/pages/LoginPage/LoginPage.jsx index c8dd1be..a63c0a8 100644 --- a/src/pages/LoginPage/LoginPage.jsx +++ b/src/pages/LoginPage/LoginPage.jsx @@ -6,7 +6,7 @@ import { PrimaryButton, SecondaryButton } from '../../components'; import { useNavigate } from 'react-router-dom'; // import { kakaoLoginAPI, getUserInfo } from '../../apis/login'; -import { kakaoLoginAPI } from '../../apis/login'; +import { kakaoLoginAPI } from '../../apis'; export default function LoginPage() { const navigate = useNavigate();