-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat:카카오로그인 구현중
- Loading branch information
Showing
14 changed files
with
181 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const dummyChatMessages1 = [ { | ||
"username" : "pjh2", | ||
"nickname" : "justin", | ||
"message" : "거기는 어때?", | ||
"sendAt" : "2024-08-18T21:01:13.382868" | ||
}, { | ||
"username" : "pjh2", | ||
"nickname" : "justin", | ||
"message" : "엄청 더워...", | ||
"sendAt" : "2024-08-18T21:01:13.382866" | ||
}, { | ||
"username" : "문보경", | ||
"nickname" : "park", | ||
"message" : "거기 날씨 어때?", | ||
"sendAt" : "2024-08-18T21:01:13.382864" | ||
}, { | ||
"username" : "문보경", | ||
"nickname" : "park", | ||
"message" : "반가워", | ||
"sendAt" : "2024-08-18T21:01:13.38286" | ||
}, { | ||
"username" : "pjh2", | ||
"nickname" : "justin", | ||
"message" : "안녕", | ||
"sendAt" : "2024-08-18T21:01:13.382837" | ||
} ] | ||
|
||
|
||
export default dummyChatMessages1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useEffect } from "react"; | ||
import {useLocation, useNavigate} from "react-router-dom"; | ||
import axios from "axios"; | ||
|
||
const KakaoRedirect = () => { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
|
||
const searchParams = new URLSearchParams(location.search); | ||
const code = searchParams.get("code"); | ||
|
||
if (code) { | ||
console.log("인가 코드:", code); | ||
// 백엔드로 넘겨주기 구현 필요! | ||
getAccessToken(code); | ||
} else { | ||
console.error("카카오 로그인 실패: 인가 코드를 받지 못했습니다."); | ||
} | ||
}, [location]); | ||
|
||
// 인가 코드를 통해 토큰을 받아오는 함수 | ||
const getAccessToken = async (code) => { | ||
try { | ||
const response = await axios.post( | ||
`https://kauth.kakao.com/oauth/token`, | ||
null, { | ||
params: { | ||
grant_type: "authorization_code", | ||
client_id: import.meta.env.VITE_KAKAO_CLIENT_ID, | ||
redirect_uri: import.meta.env.VITE_KAKAO_REDIRECT_URI, | ||
code: code, | ||
}, | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
} | ||
} | ||
); | ||
console.log("Access Token:", response.data.access_token); | ||
// 받은 토큰을 localStorage 또는 백엔드로 전달 | ||
localStorage.setItem("kakao_access_token", response.data.access_token); | ||
navigate("/join") | ||
|
||
} catch (error) { | ||
console.error("토큰 요청 실패:", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>카카오 로그인 중...</h2> | ||
</div> | ||
); | ||
}; | ||
|
||
export default KakaoRedirect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ export default defineConfig({ | |
define: { | ||
global: 'window', // 글로벌 변수를 브라우저 환경에서 사용할 수 있도록 설정 | ||
}, | ||
}); | ||
|
||
}); |