-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat/#138] 카카오로그인 구현 완료 #145
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5e121d1
fix: 로그인 코드 수정
thisishwarang 9dc8386
Merge branch 'develop' into feat/#138/KakaoLogin
thisishwarang d0ba0a6
fix: queryKey, 경로 위치 이동
thisishwarang 6460882
fix: 코드 수정 중
thisishwarang ca0fb61
fix: kakaoLogin 성공
thisishwarang 3661f48
fix: body에 redirectUri 넣기로 수정
thisishwarang 26d943e
fix: 코드리뷰 반영
thisishwarang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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,50 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { AxiosResponse } from 'axios'; | ||
|
||
import { post } from '@apis/instance'; | ||
|
||
import { END_POINT, queryKey } from '@constants'; | ||
import { useEasyNavigate } from '@hooks'; | ||
|
||
import { ApiResponseType, LoginSuccessResponse } from '@types'; | ||
|
||
const postKakaoLogin = async ( | ||
authCode: string | ||
): Promise<AxiosResponse<ApiResponseType<LoginSuccessResponse>>> => { | ||
const response = await post<ApiResponseType<LoginSuccessResponse>>( | ||
END_POINT.KAKAO_LOGIN, | ||
{ | ||
socialType: 'KAKAO', | ||
}, | ||
{ | ||
headers: { | ||
Authorization: authCode, | ||
}, | ||
} | ||
); | ||
|
||
return response; | ||
}; | ||
|
||
export const usePostKakaoLogin = () => { | ||
const queryClient = useQueryClient(); | ||
const { goHomePage } = useEasyNavigate(); | ||
|
||
return useMutation({ | ||
mutationFn: (authCode: string) => postKakaoLogin(authCode), | ||
onSuccess: (response) => { | ||
const resData = response.data.data; | ||
if (resData) { | ||
const { userId, userName } = resData; | ||
const user = { userId, userName }; | ||
localStorage.setItem('user', JSON.stringify(user)); | ||
|
||
queryClient.invalidateQueries({ queryKey: [queryKey.KAKAO_LOGIN] }); | ||
goHomePage(); | ||
} | ||
}, | ||
onError: (error) => { | ||
console.log(error); | ||
}, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const queryKey = { | ||
STORE_RANK: 'storeRank', | ||
KAKAO_LOGIN: 'kakaoLogin', | ||
} as const; |
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { StrictMode } from 'react'; | ||
// import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import App from './App.tsx'; | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<App /> | ||
</StrictMode> | ||
); | ||
createRoot(document.getElementById('root')!).render(<App />); |
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,18 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { usePostKakaoLogin } from '@apis/auth/usePostKakaoLogin'; | ||
|
||
const Redirection = () => { | ||
const code: string = | ||
new URL(window.location.href).searchParams.get('code') || ''; | ||
window.history.forward(); | ||
const { mutate } = usePostKakaoLogin(); | ||
|
||
useEffect(() => { | ||
if (code) mutate(code); | ||
}, [code, mutate]); | ||
|
||
return <div></div>; | ||
}; | ||
|
||
export default Redirection; |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import LoginPage from './LoginPage/LoginPage'; | ||
export { LoginPage }; | ||
import Redirection from './Redirection/Redirection'; | ||
|
||
export { LoginPage, Redirection }; |
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { LoginPage } from '@pages/auth/page'; | ||
import { LoginPage, Redirection } from '@pages/auth/page'; | ||
|
||
import routePath from './routePath'; | ||
|
||
import { RouteType } from '@types'; | ||
|
||
|
||
const authRoutes: RouteType[] = [ | ||
{ | ||
path: routePath.LOGINPAGE, | ||
element: <LoginPage />, | ||
}, | ||
{ | ||
path: routePath.KAKAO_REDIRECTION, | ||
element: <Redirection />, | ||
}, | ||
]; | ||
|
||
export default authRoutes; |
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,4 @@ | ||
export interface LoginSuccessResponse { | ||
userId: number; | ||
userName: string; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// 공통으로 사용되는 타입들을 정의합니다. | ||
|
||
export interface ApiResponseType<T> { | ||
code: number; | ||
message: string; | ||
|
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,7 @@ | ||
export const getToken = () => { | ||
return localStorage.getItem('user'); | ||
}; | ||
|
||
export const isLoggedIn = () => { | ||
return getToken() ? true : false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어차피 true 또는 false로 반환되는 거면 삼항연산자보다 Boolean 함수가 더 적절해보입니다..! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋네요! 반영하겠습니다! |
||
}; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './getMarkerIcon'; | ||
export * from './formatHours'; | ||
export * from './formatHours'; | ||
export * from './auth'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goHome을 작성해준다면 forward()는 불필요할 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로그인 성공시 사용자가 브라우저 뒤로가기를 했을 때 카카오로그인 관련 url로 되돌아 가는것을 방지하기 위함입니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 그런거군요!!! 새롭게 알아갑니다💡