File tree 2 files changed +12
-7
lines changed
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ interface User {
17
17
exp : number ;
18
18
}
19
19
20
- const Home : NextPage = ( { fallbackData } ) => {
21
- const { data } = useSwr < User > (
20
+ const Home : NextPage < { fallbackData : User } > = ( { fallbackData } ) => {
21
+ const { data } = useSwr < User | null > (
22
22
`${ process . env . NEXT_PUBLIC_SERVER_ENDPOINT } /api/me` ,
23
23
fetcher ,
24
24
{ fallbackData }
Original file line number Diff line number Diff line change 1
1
import axios from "axios" ;
2
2
3
- const fetcher = < T > ( url : string , headers = { } ) : Promise < T > =>
4
- axios
5
- . get < T > ( url , {
3
+ const fetcher = async < T > ( url : string , headers = { } ) : Promise < T | null > => {
4
+ try {
5
+ const { data } = await axios . get < T > ( url , {
6
6
headers,
7
7
withCredentials : true ,
8
- } )
9
- . then ( ( res ) => res . data ) ;
8
+ } ) ;
9
+
10
+ return data ;
11
+ } catch ( e ) {
12
+ return null ;
13
+ }
14
+ } ;
10
15
11
16
export default fetcher ;
You can’t perform that action at this time.
0 commit comments