-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 로그인 토큰 인증이 새로고침시에도 동작하도록 최상위 컴포넌트에서 실행 #179
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable react/jsx-no-useless-fragment */ | ||
/* eslint-disable no-console */ | ||
|
||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
import useIntervalRefreshToken from '@hooks/useIntervalRefreshToken'; | ||
import { useAppSelector } from '@stores/hooks'; | ||
|
||
function RefreshTokenProvider({ children }: { children: React.ReactNode }) { | ||
const { startRefreshTokenInterval, refreshTokenClear } = useIntervalRefreshToken(); | ||
const userId = useAppSelector((state) => { return state.user.id; }); | ||
|
||
useEffect(() => { | ||
if (userId !== null) { | ||
startRefreshTokenInterval(); | ||
console.log('RefreshTokenProvider mounted'); | ||
} | ||
|
||
// cleanup 함수를 이용하여 컴포넌트가 unmount 될 때 clearInterval 호출 | ||
return () => { | ||
refreshTokenClear(); | ||
console.log('RefreshTokenProvider unmounted'); | ||
}; | ||
}, [userId]); | ||
|
||
return <>{children}</>; | ||
} | ||
|
||
export default RefreshTokenProvider; |