-
Notifications
You must be signed in to change notification settings - Fork 5
[feat, refactor] #211 Oauth 구현 #214
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
9 commits
Select commit
Hold shift + click to select a range
ff20227
feat: 카카오 로그인 버튼 클릭 시 인증 동의창 진입 및 리디렉션 처리
jjanie00 b696104
feat(KakaoLoginPage): 컴포넌트명 수정 및 searchParams 출력
jjanie00 02b2570
fix: postOauth api serverFetcher 로 수정
jjanie00 371230c
chore: 로그인 시 쿠키 설정 주석 추가
jjanie00 8f02550
feat: postOAuth 카카오 간편 로그인 api 호출 및 토큰 추출
jjanie00 ab7e12a
chore: 카카오 이미지 도메인 remotePatterns 에 등록
jjanie00 90a2665
feat: 카카오 로그인 구현 및 리디렉션 추가
jjanie00 8d3786f
chore(loginwithOauth): httpOnly 설정 주석 처리
jjanie00 66bb75f
fix: clientFetcher 과의 호환성 고려 - secure 옵션 false 및 httpOnly 설정 주석처리
jjanie00 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
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use client'; | ||
|
|
||
| import loginWithOauth from '@/app/(auth)/oauth/kakao/loginWIthOauth'; | ||
| import { useEffect } from 'react'; | ||
|
|
||
| export interface CookieSetterProps { | ||
| code: string; | ||
| state: string; | ||
| } | ||
|
|
||
| export default function CookieSetter({ code, state }: CookieSetterProps) { | ||
| useEffect(() => { | ||
| (async () => { | ||
| await loginWithOauth({ code, state }); | ||
| })(); | ||
| }, []); | ||
|
|
||
| return <div></div>; | ||
| } |
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,62 @@ | ||
| // server action | ||
| 'use server'; | ||
|
|
||
| import { CookieSetterProps } from '@/app/(auth)/oauth/kakao/CookieSetter'; | ||
| import { cookies } from 'next/headers'; | ||
|
|
||
| export default async function loginWithOauth({ | ||
| code, | ||
| state, | ||
| }: CookieSetterProps) { | ||
| const url = `${process.env.NEXT_PUBLIC_API_URL}/auth/signIn/KAKAO`; | ||
|
|
||
| const responseBody = { | ||
| state, | ||
| redirectUri: process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI as string, | ||
| token: code, | ||
| }; | ||
|
|
||
| try { | ||
| const response = await fetch(url, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', | ||
| body: JSON.stringify(responseBody), | ||
| }); | ||
| console.log('response 응답', response); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error('간편 로그인 실패'); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| const { accessToken, refreshToken, user } = data; | ||
|
|
||
| // 쿠키에 토큰과 userId 설정 | ||
| const cookieStore = cookies(); | ||
|
|
||
| cookieStore.set('accessToken', accessToken, { | ||
| path: '/', | ||
| secure: false, | ||
| //httpOnly: true, | ||
| sameSite: 'strict', | ||
| }); | ||
| cookieStore.set('refreshToken', refreshToken, { | ||
| path: '/', | ||
| secure: false, | ||
| // httpOnly: true, | ||
| sameSite: 'strict', | ||
| }); | ||
| cookieStore.set('userId', user.id.toString(), { | ||
| path: '/', | ||
| secure: false, | ||
| // httpOnly: true, | ||
| sameSite: 'strict', | ||
| }); | ||
| console.log('로그인 성공:', data); | ||
| } catch (error) { | ||
| console.error('카카오 로그인 실패', error); | ||
| } | ||
| } | ||
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,10 @@ | ||
| import CookieSetter from '@/app/(auth)/oauth/kakao/CookieSetter'; | ||
|
|
||
| export default async function KakaoLoginPage({ | ||
| searchParams, | ||
| }: { | ||
| searchParams: Promise<{ [key: string]: string | string[] | undefined }>; | ||
| }) { | ||
| const { code, state } = await searchParams; | ||
| return <CookieSetter code={code as string} state={state as string} />; | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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.
나중에 토스트 알림으로 바꿔주는건 어떨까요?