-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] OAuth 로그인 callback 로딩 스피너 구현 (#172)
* feat: OAuth 로그인 상황 callback 로딩 스피너 구현 * fix: api 호출 axios로 전환 * fix: 코드리뷰 반영 및 build에러 수정
- Loading branch information
Showing
8 changed files
with
123 additions
and
40 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 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
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 { useEffect } from 'react'; | ||
|
||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
|
||
import LoadingSpinner from '@/components/LoadingSpinner'; | ||
import { useAuth } from '@/provider/authProvider'; | ||
import { useToast } from '@/provider/toastProvider'; | ||
|
||
function OauthCallbackHandler() { | ||
const router = useRouter(); | ||
|
||
const { showToast } = useToast(); | ||
const { setIsLoggedIn } = useAuth(); | ||
|
||
const searchParams = useSearchParams(); | ||
|
||
useEffect(() => { | ||
const accessToken = searchParams.get('access_token'); | ||
const refreshToken = searchParams.get('refresh_token'); | ||
|
||
const handleLogin = () => { | ||
if (accessToken && refreshToken) { | ||
sessionStorage.setItem('accessToken', accessToken); | ||
localStorage.setItem('refreshToken', refreshToken); | ||
setIsLoggedIn(true); | ||
showToast('success', '로그인 되었습니다.'); | ||
|
||
router.push('/'); | ||
} else { | ||
localStorage.removeItem('refreshToken'); | ||
sessionStorage.removeItem('accessToken'); | ||
showToast('error', '로그인에 실패하였습니다.'); | ||
router.push('/login'); | ||
} | ||
}; | ||
|
||
const timer = setTimeout(handleLogin, 500); | ||
|
||
return () => clearTimeout(timer); | ||
}, [router, searchParams, setIsLoggedIn, showToast]); | ||
return ( | ||
<div> | ||
<LoadingSpinner /> | ||
</div> | ||
); | ||
} | ||
|
||
export default OauthCallbackHandler; |
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,17 @@ | ||
'use client'; | ||
|
||
import { Suspense } from 'react'; | ||
|
||
import OauthCallbackHandler from './OauthCallbackHandler'; | ||
|
||
// TODO 로그인을 이미 했다면 로그인 페이지로 못들어가게 하기 | ||
|
||
function Oauthcallback() { | ||
return ( | ||
<Suspense fallback="OauthCallbackHandler"> | ||
<OauthCallbackHandler /> | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default Oauthcallback; |
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 @@ | ||
import { style, keyframes } from '@vanilla-extract/css'; | ||
|
||
import colors from '@/styles/color'; | ||
|
||
const spin = keyframes({ | ||
'0%': { transform: 'rotate(0deg)' }, | ||
'100%': { transform: 'rotate(360deg)' }, | ||
}); | ||
|
||
export const spinnerContainer = style({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100vh', | ||
width: '100%', | ||
}); | ||
|
||
export const spinner = style({ | ||
width: '48px', | ||
height: '48px', | ||
border: '6px solid #f3f3f3', | ||
borderTop: `6px solid ${colors.primary9}`, | ||
borderRadius: '50%', | ||
animation: `${spin} 1s linear infinite`, | ||
}); |
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,11 @@ | ||
import * as S from './LoadingSpinner.css'; | ||
|
||
function LoadingSpinner() { | ||
return ( | ||
<div className={S.spinnerContainer}> | ||
<div className={S.spinner} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default LoadingSpinner; |