-
Notifications
You must be signed in to change notification settings - Fork 0
인증 시스템 개선 및 카카오 로그인 추가 #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d75f6d3
style: import 순서 변경
yoouyeon 2f62b4e
feat: 카카오 로그인 기능 추가 및 리다이렉트 URI 설정
yoouyeon 2d11ed2
remove: 온보딩 페이지 스타일과 컴포넌트 파일 제거
yoouyeon 3c1d41c
refactor: protected route 추가
yoouyeon 96513ef
Merge branch 'develop' into feat/MOD-71
yoouyeon 2f516d5
refactor: QueryClient를 분리해 loader에서 사용 가능하도록 개선
yoouyeon 71e2612
refactor: 카카오 로그인 과정을 유틸함수로 분리
yoouyeon f5be141
feat: 인증 체크 API 추가
yoouyeon fb9522f
refactor: checkAuth 로더에 인증 체크 API 적용
yoouyeon c5bd1ee
revert: 온보딩 페이지 다시 추가
yoouyeon c0e2788
docs: pr 템플릿에 코드래빗 제목 생성 설명 추가
yoouyeon 4d50891
feat: "protected" route에 Outlet 컴포넌트 명시적으로 추가
yoouyeon e2897a6
chore: 사용하지 않는 useGetAuth hook 제거
yoouyeon 5c7075b
refactor: 불필요한 window check 제거
yoouyeon caf724b
chore: 사용자 목데이터 의미에 맞게 수정
yoouyeon 03d8cf0
feat: 카카오 OAuth 환경 변수 체크 추가
yoouyeon e98a767
Merge branch 'develop' into feat/MOD-71
yoouyeon 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| <!--PR 제목에 "@coderabbitai 제목" 이 들어있으면 CodeRabbit이 자동으로 제목을 생성해줍니다!--> | ||
|
|
||
| ## 💻 작업 내용 | ||
|
|
||
| <!--구현한 내용을 설명해주세요.--> | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 +1,31 @@ | ||
| import { redirect } from 'react-router'; | ||
| import { ROUTE } from '@/shared/config/route'; | ||
| import { queryClient } from '@/shared/api/queryClient'; | ||
| import { getAuth } from '../api/auth'; | ||
|
|
||
| /** | ||
| * 페이지에 접근하기 전에 실행되는 함수 | ||
| * -> accessToken이 있는지 확인하고, 없으면 login 으로 redirect | ||
| * | ||
| * @Todo accessToken 및 refreshToken 저장 방식 수정 후 로직 추가 | ||
| * 1. 메모리(전역상태변수로 관리)의 accessToken 존재 여부 확인 | ||
| * 2. 메모리에 accessToken이 없다면 httpOnly 쿠키를 확인 -> refreshToken API 호출(refreshToken으로 accessToken 재발급) | ||
| * 3. 쿠키에 refreshToken이 없다면 로그인 페이지로 redirect | ||
| * */ | ||
| const checkAuth = () => { | ||
| const token = localStorage.getItem('accessToken'); | ||
| if (!token) { | ||
| const checkAuth = async () => { | ||
| try { | ||
| const user = await queryClient.ensureQueryData({ | ||
| queryKey: ['auth', 'user'], | ||
| queryFn: getAuth, | ||
| staleTime: 5 * 60 * 1000, // 5 minutes | ||
| gcTime: 10 * 60 * 1000, // 10 minutes | ||
| }); | ||
|
|
||
| if (!user || !user.authenticated) { | ||
| throw new Error('Unauthorized'); | ||
| } | ||
|
|
||
| return user; | ||
| } catch { | ||
| // NOTE - 로그인 성공 후 이전 페이지로 돌아가기 위한 로직 | ||
| // const redirectTo = new URL(request.url).pathname; | ||
| // return redirect(`${ROUTE.login}?redirectTo=${redirectTo}`); | ||
| return redirect(ROUTE.login); | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| export default checkAuth; |
This file contains hidden or 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,17 @@ | ||
| const KAKAO_CLIENT_ID = import.meta.env.VITE_KAKAO_CLIENT_ID; | ||
| const KAKAO_REDIRECT_URI = import.meta.env.VITE_KAKAO_REDIRECT_URI; | ||
|
|
||
| if (!KAKAO_CLIENT_ID || !KAKAO_REDIRECT_URI) { | ||
| throw new Error('카카오 OAuth에 필요한 환경 변수가 설정되지 않았습니다.'); | ||
| } | ||
|
|
||
| function kakaoLogin(url?: string) { | ||
| const defaultRedirectUrl = window.location.origin; | ||
| const redirectUrl = url || defaultRedirectUrl; | ||
|
|
||
| window.location.href = `https://kauth.kakao.com/oauth/authorize?client_id=${KAKAO_CLIENT_ID}&redirect_uri=${KAKAO_REDIRECT_URI}&response_type=code&state=${encodeURIComponent( | ||
| redirectUrl | ||
| )}`; | ||
| } | ||
|
|
||
| export default kakaoLogin; | ||
This file contains hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
| import { QueryClient } from '@tanstack/react-query'; | ||
|
|
||
| export const queryClient = new QueryClient(); | ||
|
|
||
| export const setupQueryClient = ( | ||
| handleQueryError: (error: Error) => void, | ||
| handleMutationError: (error: Error) => void | ||
| ) => { | ||
| queryClient.setDefaultOptions({ | ||
| mutations: { | ||
| onError: handleMutationError, | ||
| throwOnError: true, // 기본적으로 RouteErrorBoundary로 에러를 던집니다. | ||
| }, | ||
| queries: { | ||
| throwOnError: true, // 기본적으로 RouteErrorBoundary로 에러를 던집니다. | ||
| }, | ||
| }); | ||
| queryClient.getQueryCache().config.onError = handleQueryError; | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.