-
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.
- Loading branch information
1 parent
c080156
commit 233410b
Showing
8 changed files
with
71 additions
and
29 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
39 changes: 31 additions & 8 deletions
39
app/(route)/oauth/callback/kakao/_components/callback/index.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 |
---|---|---|
@@ -1,20 +1,43 @@ | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
import React, { useEffect } from 'react' | ||
import Loading from '@/app/_common/loading' | ||
import { userKakaoTokenAtom } from '@/app/_store/atom' | ||
import axiosInstance from '@/app/_utils/axios' | ||
import { useRouter, useSearchParams } from 'next/navigation' | ||
import { useEffect } from 'react' | ||
import { useRecoilState } from 'recoil' | ||
|
||
function Callback() { | ||
const router = useRouter() | ||
const params = useSearchParams() | ||
const codeParam = params.get('code') | ||
const [, setLoginUser] = useRecoilState(userKakaoTokenAtom) | ||
|
||
useEffect(() => { | ||
const codeParam = params.get('code') | ||
async function postOAuth(code: string) { | ||
const response = await axiosInstance.post(`api/auth/kakao/signin`, { | ||
code, | ||
}) | ||
|
||
return response | ||
} | ||
|
||
if (codeParam) { | ||
console.log(codeParam) | ||
useEffect(() => { | ||
const handleLogin = async () => { | ||
if (codeParam) { | ||
try { | ||
const data = await postOAuth(codeParam) | ||
localStorage.setItem('accessToken', data.data.token) | ||
setLoginUser(data.data.token) | ||
router.push('/main') | ||
} catch (error) { | ||
console.error('인증 코드가 존재하지 않습니다.') | ||
} | ||
} | ||
} | ||
}, [params]) | ||
handleLogin() | ||
}, []) | ||
|
||
return <div>Redirecting...</div> | ||
return <Loading /> | ||
} | ||
|
||
export default Callback |
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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
.wrapper { | ||
position: fixed; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
position: fixed; | ||
|
||
top: 0; | ||
width: 480px; | ||
min-height: 100vh; | ||
height: auto; | ||
color: white; | ||
font-size: 1.4rem; | ||
letter-spacing: 0.2px; | ||
margin-top: 10px; | ||
background-color: var(--purple-700); | ||
} |
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