File tree Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Original file line number Diff line number Diff line change 1
1
import { useEffect } from 'react' ;
2
+
2
3
import { signOut } from 'next-auth/react' ;
3
4
4
5
const useFetchInterceptor = ( ) => {
5
- useEffect ( ( ) => {
6
- const handleResponse = ( response : Response ) => {
7
- if ( response . status === 401 ) {
8
- const currentUrl = window . location . href ;
9
- signOut ( { callbackUrl : `/api/auth/signin?error=SessionRequired&callbackUrl=${ encodeURIComponent ( currentUrl ) } ` } ) ;
10
- }
11
- return response ;
12
- } ;
6
+ useEffect ( ( ) => {
7
+ const handleResponse = ( response : Response ) => {
8
+ if ( response . status === 401 ) {
9
+ const currentUrl = window . location . href ;
10
+ signOut ( {
11
+ callbackUrl : `/api/auth/signin?error=SessionRequired&callbackUrl=${ encodeURIComponent ( currentUrl ) } ` ,
12
+ } ) ;
13
+ }
14
+ return response ;
15
+ } ;
13
16
14
- const originalFetch = global . fetch . bind ( global ) ;
17
+ const originalFetch = global . fetch . bind ( global ) ;
15
18
16
- global . fetch = async ( input : RequestInfo | URL , init ?: RequestInit ) => {
17
- const response = await originalFetch ( input , init ) ;
18
- return handleResponse ( response ) ;
19
- } ;
19
+ global . fetch = async ( input : RequestInfo | URL , init ?: RequestInit ) => {
20
+ const response = await originalFetch ( input , init ) ;
21
+ return handleResponse ( response ) ;
22
+ } ;
20
23
21
- return ( ) => {
22
- global . fetch = originalFetch ;
23
- } ;
24
- } , [ ] ) ;
24
+ return ( ) => {
25
+ global . fetch = originalFetch ;
26
+ } ;
27
+ } , [ ] ) ;
25
28
} ;
26
29
27
30
export default useFetchInterceptor ;
Original file line number Diff line number Diff line change @@ -30,10 +30,10 @@ import {
30
30
31
31
import { getAppLogo } from '@/components/AppLogo/AppLogo' ;
32
32
import { getInitialOrchestratorConfig } from '@/configuration' ;
33
+ import useFetchInterceptor from '@/hooks/useFetchInterceptor' ;
33
34
import { TranslationsProvider } from '@/translations/translationsProvider' ;
34
35
35
36
import '../font/inter.css' ;
36
- import useFetchInterceptor from "@/hooks/useFetchInterceptor" ;
37
37
38
38
type AppOwnProps = { orchestratorConfig : OrchestratorConfig } ;
39
39
You can’t perform that action at this time.
0 commit comments