@@ -4,9 +4,7 @@ import { UserData } from '../../types/models';
44
55type SetStateCallback < T > = ( value : T | ( ( prevValue : T ) => T ) ) => void ;
66
7- const baseUrl = import . meta. env . VITE_API_URI
8- ? `${ import . meta. env . VITE_API_URI } `
9- : `${ location . origin } ` ;
7+ const baseUrl : string = process . env . VITE_API_URI || location . origin ;
108
119const config = {
1210 withCredentials : true ,
@@ -29,26 +27,16 @@ const getUser = async (
2927 const response : AxiosResponse < UserData > = await axios ( url , config ) ;
3028 const data = response . data ;
3129
32- if ( setData ) {
33- setData ( data ) ;
34- }
35- if ( setIsLoading ) {
36- setIsLoading ( false ) ;
37- }
30+ setData ?.( data ) ;
31+ setIsLoading ?.( false ) ;
3832 } catch ( error ) {
3933 const axiosError = error as AxiosError ;
40- if ( axiosError . response && axiosError . response . status === 401 ) {
41- if ( setAuth ) {
42- setAuth ( false ) ;
43- }
34+ if ( axiosError . response ?. status === 401 ) {
35+ setAuth ?.( false ) ;
4436 } else {
45- if ( setIsError ) {
46- setIsError ( true ) ;
47- }
48- }
49- if ( setIsLoading ) {
50- setIsLoading ( false ) ;
37+ setIsError ?.( true ) ;
5138 }
39+ setIsLoading ?.( false ) ;
5240 }
5341} ;
5442
@@ -69,8 +57,7 @@ const getUsers = async (
6957 const response : AxiosResponse < UserData [ ] > = await axios ( url . toString ( ) , {
7058 withCredentials : true ,
7159 } ) ;
72- const data = response . data ;
73- setData ( data ) ;
60+ setData ( response . data ) ;
7461 } catch ( error ) {
7562 if ( axios . isAxiosError ( error ) ) {
7663 if ( error . response ?. status === 401 ) {
@@ -79,7 +66,7 @@ const getUsers = async (
7966 'Failed to authorize user. If JWT auth is enabled, please check your configuration or disable it.' ,
8067 ) ;
8168 } else {
82- const msg = error . response ?. data ?. message ?? error . message ;
69+ const msg = ( error . response ?. data as any ) ?. message ?? error . message ;
8370 setErrorMessage ( `Error fetching users: ${ msg } ` ) ;
8471 }
8572 } else {
@@ -126,7 +113,7 @@ const getUserLoggedIn = async (
126113 } catch ( error ) {
127114 setIsLoading ( false ) ;
128115 const axiosError = error as AxiosError ;
129- if ( axiosError . response && axiosError . response . status === 401 ) {
116+ if ( axiosError . response ? .status === 401 ) {
130117 setAuth ( false ) ;
131118 } else {
132119 setIsError ( true ) ;
0 commit comments