-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 카카오 소셜 로그인, 유저 페이지 UI
- Loading branch information
Showing
42 changed files
with
875 additions
and
177 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
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,13 @@ | ||
import NextAuth from 'next-auth' | ||
import GoogleProvider from 'next-auth/providers/google' | ||
|
||
const handler = NextAuth({ | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: process.env.NEXT_PUBLIC_APP_GOOGLE_API_KEY || '', | ||
clientSecret: process.env.NEXT_PUBLIC_APP_GOOGLE_SECRET_KEY || '', | ||
}), | ||
], | ||
}) | ||
|
||
export { handler as GET, handler as POST } |
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,50 @@ | ||
'use client' | ||
|
||
import axios from 'axios' | ||
import { useRouter } from 'next/navigation' | ||
import { useEffect } from 'react' | ||
|
||
const KakaoLogin = () => { | ||
const router = useRouter() | ||
const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL | ||
|
||
useEffect(() => { | ||
const getToken = async () => { | ||
const AUTHORIZATION_CODE = new URL(window.location.href).searchParams.get( | ||
'code', | ||
) | ||
if (!AUTHORIZATION_CODE) { | ||
console.error('Authorization Code is missing') | ||
return | ||
} | ||
|
||
try { | ||
const res = await axios.post(`${API_BASE_URL}/kakao/login`, { | ||
idToken: AUTHORIZATION_CODE, | ||
}) | ||
|
||
if (res.data.code === 'MEMBER_002') { | ||
// 에러 코드가 MEMBER_002일 경우 이메일을 localStorage에 저장하고 회원가입 페이지로 이동 | ||
localStorage.setItem('email', res.data.message) | ||
router.push('/signin/terms') | ||
} else if (res.data.accessToken) { | ||
// 정상적으로 토큰을 받은 경우 /로 리다이렉트 | ||
localStorage.setItem('access_token', res.data.accessToken) | ||
router.push('/') | ||
} else { | ||
// 토큰이 없을 경우에도 /signin/terms로 리다이렉트 | ||
router.push('/signin/terms') | ||
} | ||
} catch (error) { | ||
console.error('Error during Kakao login:', error) | ||
router.push('/signin/terms') | ||
} | ||
} | ||
|
||
getToken() | ||
}, [router]) | ||
|
||
return null | ||
} | ||
|
||
export default KakaoLogin |
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,60 @@ | ||
'use client' | ||
|
||
import Image from 'next/image' | ||
import { useRouter } from 'next/navigation' | ||
|
||
const Signin = () => { | ||
const router = useRouter() | ||
const KAKAO_API_KEY = process.env.NEXT_PUBLIC_APP_KAKAO_API_KEY | ||
const KAKAO_REDIRECT_URI = process.env.NEXT_PUBLIC_APP_KAKAO_REDIRECT_URI | ||
const GOOGLE_API_KEY = process.env.NEXT_PUBLIC_APP_GOOGLE_API_KEY | ||
const GOOGLE_REDIRECT_URI = process.env.NEXT_PUBLIC_APP_GOOGLE_REDIRECT_URI | ||
|
||
const KakaoSigninBtnClick = () => { | ||
const URL = `https://kauth.kakao.com/oauth/authorize?client_id=${KAKAO_API_KEY}&redirect_uri=${KAKAO_REDIRECT_URI}&response_type=code&prompt=login` | ||
router.push(URL) | ||
} | ||
|
||
const GoogleSigninBtnClick = () => { | ||
const URL = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_API_KEY}&redirect_uri=${GOOGLE_REDIRECT_URI}&response_type=code&scope=https://www.googleapis.com/auth/userinfo.email` | ||
router.push(URL) | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col items-center my-18 w-full max-w-95 mx-auto gap-5"> | ||
<Image | ||
src="/images/common/cat_logo.svg" | ||
alt="google_btn" | ||
width={83} | ||
height={73} | ||
/> | ||
<div className="text-maindark text-title1 font-bold"> | ||
로그인 / 회원가입 | ||
</div> | ||
<div className="text-gray2 text-headline font-semibold"> | ||
소셜 로그인로 가입할 수 있습니다. | ||
</div> | ||
<div className="h-[1px] bg-gray4 w-full" /> | ||
<div className="flex flex-col gap-5"> | ||
<Image | ||
src="/images/auth/google_btn.svg" | ||
alt="google_btn" | ||
width={380} | ||
height={50} | ||
className="cursor-pointer" | ||
onClick={GoogleSigninBtnClick} | ||
/> | ||
<Image | ||
src="/images/auth/kakao_btn.svg" | ||
alt="kako_btn" | ||
width={380} | ||
height={50} | ||
className="cursor-pointer" | ||
onClick={KakaoSigninBtnClick} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Signin |
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
Oops, something went wrong.