11import Cookies from 'js-cookie' ;
22import fp from '@fingerprintjs/fingerprintjs' ;
3- import { TOKEN_COOKIE_NAME } from './jwt' ;
3+ import { TOKEN_COOKIE_NAME , removeAuthToken } from './jwt' ;
44
55type HttpOptionsType = RequestInit | { headers : Record < string , any > } ;
66
@@ -30,10 +30,10 @@ type ApiReturn<ResponseType, ErrorType> = {
3030 */
3131export async function httpCall <
3232 ResponseType = AppResponse ,
33- ErrorType = AppError
33+ ErrorType = AppError ,
3434> (
3535 url : string ,
36- options ?: HttpOptionsType
36+ options ?: HttpOptionsType ,
3737) : Promise < ApiReturn < ResponseType , ErrorType > > {
3838 try {
3939 const fingerprintPromise = await fp . load ( { monitoring : false } ) ;
@@ -65,7 +65,7 @@ export async function httpCall<
6565
6666 // Logout user if token is invalid
6767 if ( data . status === 401 ) {
68- Cookies . remove ( TOKEN_COOKIE_NAME ) ;
68+ removeAuthToken ( ) ;
6969 window . location . reload ( ) ;
7070 return { response : undefined , error : data as ErrorType } ;
7171 }
@@ -92,11 +92,11 @@ export async function httpCall<
9292
9393export async function httpPost <
9494 ResponseType = AppResponse ,
95- ErrorType = AppError
95+ ErrorType = AppError ,
9696> (
9797 url : string ,
9898 body : Record < string , any > ,
99- options ?: HttpOptionsType
99+ options ?: HttpOptionsType ,
100100) : Promise < ApiReturn < ResponseType , ErrorType > > {
101101 return httpCall < ResponseType , ErrorType > ( url , {
102102 ...options ,
@@ -108,7 +108,7 @@ export async function httpPost<
108108export async function httpGet < ResponseType = AppResponse , ErrorType = AppError > (
109109 url : string ,
110110 queryParams ?: Record < string , any > ,
111- options ?: HttpOptionsType
111+ options ?: HttpOptionsType ,
112112) : Promise < ApiReturn < ResponseType , ErrorType > > {
113113 const searchParams = new URLSearchParams ( queryParams ) . toString ( ) ;
114114 const queryUrl = searchParams ? `${ url } ?${ searchParams } ` : url ;
@@ -122,11 +122,11 @@ export async function httpGet<ResponseType = AppResponse, ErrorType = AppError>(
122122
123123export async function httpPatch <
124124 ResponseType = AppResponse ,
125- ErrorType = AppError
125+ ErrorType = AppError ,
126126> (
127127 url : string ,
128128 body : Record < string , any > ,
129- options ?: HttpOptionsType
129+ options ?: HttpOptionsType ,
130130) : Promise < ApiReturn < ResponseType , ErrorType > > {
131131 return httpCall < ResponseType , ErrorType > ( url , {
132132 ...options ,
@@ -138,7 +138,7 @@ export async function httpPatch<
138138export async function httpPut < ResponseType = AppResponse , ErrorType = AppError > (
139139 url : string ,
140140 body : Record < string , any > ,
141- options ?: HttpOptionsType
141+ options ?: HttpOptionsType ,
142142) : Promise < ApiReturn < ResponseType , ErrorType > > {
143143 return httpCall < ResponseType , ErrorType > ( url , {
144144 ...options ,
@@ -149,10 +149,10 @@ export async function httpPut<ResponseType = AppResponse, ErrorType = AppError>(
149149
150150export async function httpDelete <
151151 ResponseType = AppResponse ,
152- ErrorType = AppError
152+ ErrorType = AppError ,
153153> (
154154 url : string ,
155- options ?: HttpOptionsType
155+ options ?: HttpOptionsType ,
156156) : Promise < ApiReturn < ResponseType , ErrorType > > {
157157 return httpCall < ResponseType , ErrorType > ( url , {
158158 ...options ,
0 commit comments