-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restructure login feature to FSD architecture (#11)
- Loading branch information
Showing
17 changed files
with
242 additions
and
185 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import GoogleRedirect from '@/components/Login/GoogleRedirect' | ||
import GoogleRedirect from '@/features/login/components/GoogleRedirect' | ||
|
||
export default GoogleRedirect |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import KakaoRedirect from '@/components/Login/KakaoRedirect' | ||
import KakaoRedirect from '@/features/login/components/KakaoRedirect' | ||
|
||
export default KakaoRedirect |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import KakaoRedirect from '@/components/Login/KakaoRedirect' | ||
import KakaoRedirect from '@/features/login/components/KakaoRedirect' | ||
|
||
export default KakaoRedirect |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import NaverRedirect from '@/components/Login/NaverRedirect' | ||
import NaverRedirect from '@/features/login/components/NaverRedirect' | ||
|
||
export default NaverRedirect |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
// 구글 로그인 | ||
export const googleLogin = async (code: string) => { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_LINKIT_SERVER_URL}/login/google`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json;charset=utf-8' }, | ||
credentials: 'include', | ||
body: JSON.stringify({ code }), | ||
}) | ||
|
||
if (!response.ok) throw new Error('Failed to log in with Google') | ||
|
||
return response.json() | ||
} | ||
|
||
// 카카오 로그인 | ||
export const kakaoLogin = async (code: string) => { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_LINKIT_SERVER_URL}/login/kakao`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json;charset=utf-8' }, | ||
credentials: 'include', | ||
body: JSON.stringify({ code }), | ||
}) | ||
|
||
if (!response.ok) throw new Error('Failed to log in with Kakao') | ||
|
||
return response.json() | ||
} | ||
|
||
// 네이버 로그인 | ||
export const naverLogin = async (code: string) => { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_LINKIT_SERVER_URL}/login/naver`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json;charset=utf-8' }, | ||
credentials: 'include', | ||
body: JSON.stringify({ code }), | ||
}) | ||
|
||
if (!response.ok) throw new Error('Failed to log in with Naver') | ||
|
||
return response.json() | ||
} |
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,25 @@ | ||
// src/features/auth/components/GoogleRedirect.tsx | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import { motion } from 'framer-motion' | ||
import { useGoogleAuth } from '../model/useGoogleAuth' | ||
|
||
const GoogleRedirect: React.FC = () => { | ||
const params = useSearchParams() | ||
const code = params.get('code') | ||
const { loading } = useGoogleAuth(code) | ||
|
||
return loading ? ( | ||
<div className="flex h-screen flex-col items-center justify-center"> | ||
<motion.div | ||
className="h-12 w-12 animate-spin rounded-full border-4 border-blue-200 border-t-blue-500" | ||
animate={{ rotate: 360 }} | ||
transition={{ repeat: Infinity, duration: 1 }} | ||
/> | ||
<p className="mt-4 text-lg">Loading...</p> | ||
</div> | ||
) : null | ||
} | ||
|
||
export default GoogleRedirect |
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,25 @@ | ||
// src/features/auth/components/KakaoRedirect.tsx | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import { motion } from 'framer-motion' | ||
import { useKakaoAuth } from '../model/useKakaoAuth' | ||
|
||
const KakaoRedirect: React.FC = () => { | ||
const params = useSearchParams() | ||
const code = params.get('code') | ||
const { loading } = useKakaoAuth(code) | ||
|
||
return loading ? ( | ||
<div className="flex h-screen flex-col items-center justify-center"> | ||
<motion.div | ||
className="h-12 w-12 animate-spin rounded-full border-4 border-blue-200 border-t-blue-500" | ||
animate={{ rotate: 360 }} | ||
transition={{ repeat: Infinity, duration: 1 }} | ||
/> | ||
<p className="mt-4 text-lg">Loading...</p> | ||
</div> | ||
) : null | ||
} | ||
|
||
export default KakaoRedirect |
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,25 @@ | ||
// src/features/auth/components/NaverRedirect.tsx | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import { motion } from 'framer-motion' | ||
import { useNaverAuth } from '../model/useNaverAuth' | ||
|
||
const NaverRedirect: React.FC = () => { | ||
const params = useSearchParams() | ||
const code = params.get('code') | ||
const { loading } = useNaverAuth(code) | ||
|
||
return loading ? ( | ||
<div className="flex h-screen flex-col items-center justify-center"> | ||
<motion.div | ||
className="h-12 w-12 animate-spin rounded-full border-4 border-blue-200 border-t-blue-500" | ||
animate={{ rotate: 360 }} | ||
transition={{ repeat: Infinity, duration: 1 }} | ||
/> | ||
<p className="mt-4 text-lg">Loading...</p> | ||
</div> | ||
) : null | ||
} | ||
|
||
export default NaverRedirect |
File renamed without changes.
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,6 @@ | ||
// src/features/auth/model/authTypes.ts | ||
export interface LoginResponse { | ||
accessToken: string | ||
email: string | ||
existMemberBasicInform: boolean | ||
} |
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,39 @@ | ||
'use client' | ||
// src/features/auth/hooks/useGoogleAuth.ts | ||
import { useRouter } from 'next/navigation' | ||
import { useEffect, useState } from 'react' | ||
import { useRecoilState } from 'recoil' | ||
import { accessTokenState, authState, emailState } from '@/context/recoil-context' | ||
import { googleLogin } from '../api/authApi' | ||
import { LoginResponse } from './authType' | ||
|
||
export const useGoogleAuth = (code: string | null) => { | ||
const router = useRouter() | ||
const [toEmail, setToEmail] = useRecoilState(emailState) | ||
const [accessToken, setAccessToken] = useRecoilState(accessTokenState) | ||
const [loading, setLoading] = useState(true) | ||
|
||
useEffect(() => { | ||
const login = async () => { | ||
if (!code) return | ||
try { | ||
const responseData: LoginResponse = await googleLogin(code) | ||
setAccessToken(responseData.accessToken) | ||
setToEmail(responseData.email) | ||
|
||
if (responseData.existMemberBasicInform) { | ||
router.push('/') | ||
} else { | ||
router.push('/onBoarding') | ||
} | ||
} catch (error) { | ||
console.error('Login failed:', error) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
login() | ||
}, [code, router, setToEmail, setAccessToken]) | ||
|
||
return { loading } | ||
} |
Oops, something went wrong.