File tree Expand file tree Collapse file tree 2 files changed +20
-21
lines changed Expand file tree Collapse file tree 2 files changed +20
-21
lines changed Original file line number Diff line number Diff line change 1
- import { fetchAuthSession } from "aws-amplify/auth" ;
1
+ import { fetchAuthSession , signOut } from "aws-amplify/auth" ;
2
2
3
3
export interface FetcherProps {
4
4
apiUrl : string ;
@@ -58,25 +58,26 @@ export const buildApiEndpoint = ({
58
58
59
59
export const getHeaders = async ( ) =>
60
60
fetchAuthToken ( )
61
- . then (
62
- ( idToken ) =>
63
- ( {
64
- Authorization : `Bearer ${ idToken } ` ,
65
- Accept : "application/json" ,
66
- "Content-Type" : "application/json" ,
67
- } ) as HeadersInit ,
68
- )
69
- . catch ( ( error ) => {
70
- console . error ( error ) ;
71
- throw error ;
61
+ . then ( ( idToken ) => {
62
+ if ( idToken === undefined ) throw Error ( "No idToken" ) ;
63
+ return {
64
+ Authorization : `Bearer ${ idToken } ` ,
65
+ Accept : "application/json" ,
66
+ "Content-Type" : "application/json" ,
67
+ } as HeadersInit ;
68
+ } )
69
+ . catch ( async ( ) => {
70
+ await signOut ( ) ;
72
71
} ) ;
73
72
74
73
export const getter = ( props : FetcherProps ) =>
75
- getHeaders ( ) . then ( ( headers ) =>
76
- fetch ( buildApiEndpoint ( props ) , {
77
- ...props . init ,
78
- headers,
79
- } ) . then ( ( response ) =>
80
- response . ok ? response . json ( ) : rejectApiError ( response ) ,
81
- ) ,
74
+ getHeaders ( ) . then (
75
+ ( headers ) =>
76
+ headers &&
77
+ fetch ( buildApiEndpoint ( props ) , {
78
+ ...props . init ,
79
+ headers,
80
+ } ) . then ( ( response ) =>
81
+ response . ok ? response . json ( ) : rejectApiError ( response ) ,
82
+ ) ,
82
83
) ;
Original file line number Diff line number Diff line change @@ -11,11 +11,9 @@ const AsyncErrorBoundary: FunctionComponent<PropsWithChildren> = ({
11
11
showBoundary ( event ) ;
12
12
} ;
13
13
14
- window . addEventListener ( "error" , handleError ) ;
15
14
window . addEventListener ( "unhandledrejection" , handleError ) ;
16
15
17
16
return ( ) => {
18
- window . removeEventListener ( "error" , handleError ) ;
19
17
window . removeEventListener ( "unhandledrejection" , handleError ) ;
20
18
} ;
21
19
} , [ showBoundary ] ) ;
You can’t perform that action at this time.
0 commit comments