Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ient into NABI-86
  • Loading branch information
juyeon-park committed Nov 2, 2023
2 parents 0f17fbd + ce7c767 commit 07c008d
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 40 deletions.
10 changes: 5 additions & 5 deletions src/components/domain/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const Header = ({ isLogin = false }: HeaderProps) => {
{/** TODO: 아바타 컴포넌트로 변경 */}
</>
) : (
<>
<Button variant={'gradation'}>
<Link href={AppPath.login()}>로그인</Link>
</Button>
</>
<Button variant={'gradation'}>
<Link href={AppPath.login()} scroll={false}>
로그인
</Link>
</Button>
)}
</div>
</header>
Expand Down
16 changes: 0 additions & 16 deletions src/components/domain/LoginForm/LoginForm.stories.tsx

This file was deleted.

40 changes: 39 additions & 1 deletion src/components/domain/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
'use client'

import Image from 'next/image'
import { useRouter } from 'next/navigation'
import AppPath from '@/config/appPath'
import Assets from '@/config/assets'
import { getGoogleLogin, getKakaoLogin } from '@/services/auth/auth'
import LoginButtons from './section/LoginButtons'

const LoginForm = () => {
const router = useRouter()
const kakaoLoginHandler = async () => {
try {
await getKakaoLogin()
const res = await getKakaoLogin()
const data = await res.json()
console.log(data)
alert('로그인 성공')
router.back()
} catch (e) {
console.log(e)
alert('로그인 실패')
router.push(AppPath.login(), { scroll: false })
}
}
const googleLoginHandler = async () => {
try {
await getKakaoLogin()
const res = await getGoogleLogin()
const data = await res.json()
console.log(data)
alert('로그인 성공')
router.back()
} catch (e) {
console.log(e)
alert('로그인 실패')
router.push(AppPath.login(), { scroll: false })
}
}

return (
<section className="flex flex-col items-center justify-center w-full h-full gap-4">
<Image className="mb-20" src={Assets.logo} alt="nabi-logo" />
<LoginButtons />
<LoginButtons
kakaoLoginHandler={kakaoLoginHandler}
googleLoginHandler={googleLoginHandler}
/>
</section>
)
}
Expand Down
14 changes: 11 additions & 3 deletions src/components/domain/LoginForm/section/LoginButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
import React from 'react'
import { KakaoLoginButton, GoogleLoginButton } from '../../buttons/LoginButtons'

const LoginButtons = () => {
type LoginButtonsProps = {
kakaoLoginHandler: () => void
googleLoginHandler: () => void
}

const LoginButtons = ({
kakaoLoginHandler,
googleLoginHandler,
}: LoginButtonsProps) => {
return (
<section className="flex flex-col gap-2">
<KakaoLoginButton onClickButton={() => alert('k')} />
<GoogleLoginButton onClickButton={() => alert('g')} />
<KakaoLoginButton onClickButton={kakaoLoginHandler} />
<GoogleLoginButton onClickButton={googleLoginHandler} />
</section>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ApiEndPoint = {
login: () => '/login',
kakaoLogin: () => '/oauth2/authorize/kakao/login',
googleLogin: () => '/oauth2/authorize/google/login',
test: () => '/test',
item: (itemId:string) => `/${itemId}`
} as const
Expand Down
46 changes: 46 additions & 0 deletions src/lib/msw/mocks/authHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { rest } from 'msw'
import ApiEndPoint from '@/config/apiEndPoint'
import { Environment } from '@/config/environment'

const baseUrl = Environment.apiAddress()

const authHandlers = [
rest.get(`${baseUrl}${ApiEndPoint.kakaoLogin()}`, async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
data: {
userInfo: {
userId: 1,
nickname: '병원에 간 미어캣',
imageUrl: 'http://asdf~',
},
token: {
accessToken: 'asdfasdf',
refreshToken: 'asdfa',
},
},
}),
)
}),
rest.get(`${baseUrl}${ApiEndPoint.googleLogin()}`, async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
data: {
userInfo: {
userId: 1,
nickname: '병원에 간 미어캣',
imageUrl: 'http://asdf~',
},
token: {
accessToken: 'asdfasdf',
refreshToken: 'asdfa',
},
},
}),
)
}),
]

export default authHandlers
5 changes: 3 additions & 2 deletions src/lib/msw/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { itemHandlers } from './itemHandlers'
import authHandlers from './authHandlers'
import { testHandlers } from './testHandler'
import { itemHandlers } from './itemHandlers'

export const handlers = [...testHandlers, ...itemHandlers]
export const handlers = [...testHandlers, ...authHandlers, ...itemHandlers]
25 changes: 13 additions & 12 deletions src/services/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import ApiEndPoint from '@/config/apiEndPoint'
import { Environment } from '@/config/environment'

const postLogin = async () => {
const response = await fetch(Environment.apiAddress() + ApiEndPoint.login(), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
const data = await response.json()
return data
import apiClient from '../apiClient'

const getKakaoLogin = async () => {
const response = await apiClient.get(ApiEndPoint.kakaoLogin())

return response
}

const getGoogleLogin = async () => {
const response = await apiClient.get(ApiEndPoint.googleLogin())

return response
}

export { postLogin }
export { getKakaoLogin, getGoogleLogin }

0 comments on commit 07c008d

Please sign in to comment.