-
Notifications
You must be signed in to change notification settings - Fork 3
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
Next Auth 카카오 로그인 #63
Merged
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2dbbde7
feat: next-auth kakao login
oyeon-kwon 648aeff
feat: next auth kakao login 구현 및 테스트 코드 추가
oyeon-kwon d3db6fe
Update index.tsx
oyeon-kwon db126e2
Update KakaoLogin.test.tsx
oyeon-kwon 8977a44
fix: page extension 추가
hyesungoh 500e1bc
fix: lint 수정
oyeon-kwon 2a0b772
chore: fix lint
hyesungoh 458e52a
fix: storybook session-provider 사용
hyesungoh 4fd3914
chore: 환경 변수 타입 추가
hyesungoh 9b76c15
test: mock fn 타입 설정
hyesungoh ac9605c
Merge branch 'issue/44' of https://github.com/depromeet/13th-3team-cl…
oyeon-kwon d394aa8
fix: env 변수명 변경
oyeon-kwon 6d7e4bf
fix: cloudflare preview 환경에서 대응 가능하도록 처리
oyeon-kwon e863953
fix: 환경설정 타입 추가
oyeon-kwon 68c0f04
fix: next-auth 재설치
oyeon-kwon a70196d
Update index.page.tsx
oyeon-kwon ae07a73
Update index.page.tsx
oyeon-kwon d585055
Update index.page.tsx
oyeon-kwon fc978d4
Update index.page.tsx
oyeon-kwon 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+130 KB
.yarn/cache/preact-render-to-string-npm-5.2.6-5999db0763-be8d5d8fb5.zip
Binary file not shown.
Binary file not shown.
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,63 @@ | ||
import { signIn, signOut, useSession } from 'next-auth/react'; | ||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'; | ||
import { afterEach, beforeEach, describe, expect, type Mock, test, vi } from 'vitest'; | ||
|
||
import KakaoLoginButton from './KakaoLoginButton'; | ||
|
||
describe('components/kakaoLoginButton/KakaoLoginButton', () => { | ||
vi.mock('next-auth/react', () => ({ | ||
signIn: vi.fn(), | ||
signOut: vi.fn(), | ||
useSession: vi.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
// useSession 함수의 반환 값을 설정 | ||
(useSession as Mock<unknown[]>).mockReturnValue({ data: null }); | ||
}); | ||
|
||
afterEach(cleanup); | ||
|
||
test('정의되어 있어야 한다', () => { | ||
expect(KakaoLoginButton).toBeDefined(); | ||
}); | ||
|
||
test('유저가 로그인하지 않은 경우에는 카카오로 로그인 하기 버튼을 렌더링한다', () => { | ||
render(<KakaoLoginButton />); | ||
expect(screen.getByRole('button')).toHaveTextContent('카카오로 로그인 하기'); | ||
}); | ||
|
||
test('유저가 로그인한 경우에는 유저를 환영하는 문구와 "로그아웃 하기" 버튼을 렌더링한다', () => { | ||
(useSession as Mock<unknown[]>).mockReturnValue({ | ||
data: { | ||
user: { | ||
name: '오연', | ||
}, | ||
}, | ||
}); | ||
render(<KakaoLoginButton />); | ||
expect(screen.getByText('오연님 환영합니다.')).toBeInTheDocument(); | ||
expect(screen.getByRole('button')).toHaveTextContent('로그아웃 하기'); | ||
}); | ||
|
||
test('"로그아웃 하기" 버튼을 클릭하면 signOut 함수를 호출한다', () => { | ||
(useSession as Mock<unknown[]>).mockReturnValue({ | ||
data: { | ||
user: { | ||
name: '오연', | ||
}, | ||
}, | ||
}); | ||
render(<KakaoLoginButton />); | ||
const logoutButton = screen.getByRole('button', { name: '로그아웃 하기' }); | ||
fireEvent.click(logoutButton); | ||
expect(signOut).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('"카카오로 로그인 하기" 버튼을 클릭하면 signIn 함수를 호출한다', () => { | ||
render(<KakaoLoginButton />); | ||
const loginButton = screen.getByRole('button', { name: '카카오로 로그인 하기' }); | ||
fireEvent.click(loginButton); | ||
expect(signIn).toHaveBeenCalledWith('kakao'); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/components/kakaoLoginButton/KakaoLoginButton.stories.tsx
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,21 @@ | ||
import { SessionProvider } from 'next-auth/react'; | ||
import { type Meta, type StoryObj } from '@storybook/react'; | ||
|
||
import KakaoLoginButton from './KakaoLoginButton'; | ||
|
||
const meta: Meta<typeof KakaoLoginButton> = { | ||
title: 'KakaoLoginButton', | ||
component: KakaoLoginButton, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof KakaoLoginButton>; | ||
|
||
export const Primary: Story = { | ||
render: () => ( | ||
<SessionProvider> | ||
<KakaoLoginButton /> | ||
</SessionProvider> | ||
), | ||
}; |
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,26 @@ | ||
import React from 'react'; | ||
import { signIn, signOut, useSession } from 'next-auth/react'; | ||
|
||
const KakaoLoginButton = () => { | ||
const { data: session } = useSession(); | ||
|
||
if (session) { | ||
// TODO : 추후 서버로 session.user.name 과 session.user.email 정보를 보내줄 수 있음 | ||
return ( | ||
<> | ||
<div>{session.user?.name}님 환영합니다.</div> | ||
<button type="button" onClick={() => signOut()}> | ||
로그아웃 하기 | ||
</button> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<button type="button" onClick={() => signIn('kakao')}> | ||
카카오로 로그인 하기 | ||
</button> | ||
); | ||
}; | ||
|
||
export default KakaoLoginButton; |
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.
👍