Skip to content

Commit

Permalink
refactor: 로그인 관련 훅 생성 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddhelop committed Oct 27, 2024
1 parent 32159f5 commit fd4b6e7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Metadata, Viewport } from 'next'
import localFont from 'next/font/local'

import Footer from '@/components/Layout/Footer'
import { GoogleAnalytics } from '@next/third-parties/google'

import './globals.css'
Expand All @@ -14,6 +13,7 @@ import ClientProvider from '@/components/common/ClientProvider'
import 'react-toastify/dist/ReactToastify.css'
import { ToastContainer } from 'react-toastify'
import Header from '@/widgets/Header/Header'
import Footer from '@/widgets/Footer/Footer'

export const metadata: Metadata = {
title: '링킷, Linkit',
Expand Down
5 changes: 5 additions & 0 deletions src/app/login/onboarding-info/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import OnBoardingInfo from '@/features/onBoarding/components/OnBoardingInfo'

export default function OnBoardingInfoPage() {
return <OnBoardingInfo />
}
8 changes: 5 additions & 3 deletions src/features/login/model/authType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// src/features/auth/model/authTypes.ts
export interface LoginResponse {
accessToken: string
email: string
existMemberBasicInform: boolean
result: {
accessToken: string
email: string
existMemberBasicInform: boolean
}
}
15 changes: 8 additions & 7 deletions src/features/login/model/useKakaoAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import { useRouter } from 'next/navigation'
import { useEffect, useState } from 'react'
import { useRecoilState } from 'recoil'
import { accessTokenState, emailState } from '@/context/recoil-context'
import { accessTokenState } from '@/context/recoil-context'
import { kakaoLogin } from '../api/authApi'
import { LoginResponse } from './authType'

export const useKakaoAuth = (code: string | null) => {
const router = useRouter()
const [toEmail, setToEmail] = useRecoilState(emailState)
const [accessToken, setAccessToken] = useRecoilState(accessTokenState)
const [loading, setLoading] = useState(true)

Expand All @@ -17,13 +16,15 @@ export const useKakaoAuth = (code: string | null) => {
if (!code) return
try {
const responseData: LoginResponse = await kakaoLogin(code)
setAccessToken(responseData.accessToken)
setToEmail(responseData.email)

if (responseData.existMemberBasicInform) {
setAccessToken(responseData.result.accessToken)

if (responseData.result.existMemberBasicInform) {
router.push('/')
} else {
router.push('/onBoarding')
// URL에 이메일과 이름을 쿼리 파라미터로 포함하여 온보딩 페이지로 이동
const email = responseData.result.email
router.push(`/login/onboarding-info?email=${email}`)
}
} catch (error) {
console.error('Login failed:', error)
Expand All @@ -32,7 +33,7 @@ export const useKakaoAuth = (code: string | null) => {
}
}
login()
}, [code, router, setToEmail, setAccessToken])
}, [code, router, setAccessToken])

return { loading }
}
3 changes: 3 additions & 0 deletions src/features/onBoarding/components/OnBoardingInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function OnBoardingInfo() {
return <div></div>
}

0 comments on commit fd4b6e7

Please sign in to comment.