File tree Expand file tree Collapse file tree 5 files changed +56
-12
lines changed Expand file tree Collapse file tree 5 files changed +56
-12
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import Header from '@/shared/components/header/Header';
55import FooterWrapper from '@/shared/components/footer/FooterWrapper' ;
66import ScrollTopBtnWrapper from '@/shared/components/scroll-top/ScrollTopBtnWrapper' ;
77import KaKaoScript from './api/kakao/KaKaoScript' ;
8- import IdleHandler from '@/domains/login/components/IdleHandler' ;
98import Provider from '@/shared/api/Provider' ;
9+ import ClientInitHook from '@/domains/login/components/ClientInitHook' ;
1010
1111export const metadata : Metadata = {
1212 title : { default : 'SSOUL' , template : 'SSOUL | %s' } ,
@@ -24,7 +24,7 @@ export default function RootLayout({
2424 < body className = "relative flex flex-col min-h-screen" >
2525 < Provider >
2626 < Header />
27- < IdleHandler />
27+ < ClientInitHook />
2828 < main className = "flex flex-1 pt-[2.75rem] md:pt-[3.75rem]" > { children } </ main >
2929 < FooterWrapper />
3030
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useFetchInterceptor } from '@/shared/hook/useFetchInterceptor' ;
4+ import { useIdleLogout } from '../hook/useIdleLogout' ;
5+
6+ function ClientInitHook ( ) {
7+ useIdleLogout ( ) ;
8+ useFetchInterceptor ( ) ;
9+ return null ;
10+ }
11+ export default ClientInitHook ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import CocktailSearchBar from './CocktailSearchBar';
1010import useSearchControl from '../../hook/useSearchControl' ;
1111import CocktailSearch from '../../api/CocktailSearch' ;
1212
13-
1413function Cocktails ( ) {
1514 const [ data , setData ] = useState < Cocktail [ ] > ( [ ] ) ;
1615 const [ lastId , setLastId ] = useState < number | null > ( null ) ;
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useEffect } from 'react' ;
4+ import { getApi } from '@/app/api/config/appConfig' ;
5+ import { useRouter } from 'next/navigation' ;
6+ import { useToast } from '@/shared/hook/useToast' ;
7+
8+ export const useFetchInterceptor = ( ) => {
9+ const router = useRouter ( ) ;
10+ const { toastInfo } = useToast ( ) ;
11+
12+ useEffect ( ( ) => {
13+ const originalFetch = global . fetch ;
14+
15+ ( global . fetch as typeof global . fetch ) = async ( input , init ?) => {
16+ const response = await originalFetch ( input , { ...init , credentials : 'include' } ) ;
17+
18+ if ( response . status === 401 ) {
19+ try {
20+ const refreshRes = await originalFetch ( `${ getApi } /user/auth/refresh` , {
21+ method : 'POST' ,
22+ credentials : 'include' ,
23+ } ) ;
24+
25+ if ( refreshRes . ok ) {
26+ return originalFetch ( input , { ...init , credentials : 'include' } ) ;
27+ } else {
28+ toastInfo ( '로그인 인증 만료로 다시 로그인해주세요.' ) ;
29+ router . push ( '/login' ) ;
30+ }
31+ } catch {
32+ toastInfo ( '로그인 인증 만료로 다시 로그인해주세요.' ) ;
33+ router . push ( '/login' ) ;
34+ }
35+ }
36+ return response ;
37+ } ;
38+
39+ return ( ) => {
40+ global . fetch = originalFetch ;
41+ } ;
42+ } , [ router , toastInfo ] ) ;
43+ } ;
You can’t perform that action at this time.
0 commit comments