From f03f33f6795ebad0db0cfb283e9b1dd6d56eb0c7 Mon Sep 17 00:00:00 2001 From: Gitanjli <96485413+gitanjli525@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:20:51 +0530 Subject: [PATCH] feat: signout api call (#583) Co-authored-by: Pritish Budhiraja <1805317@kiit.ac.in> --- src/screens/APIUtils/APIUtils.res | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/screens/APIUtils/APIUtils.res b/src/screens/APIUtils/APIUtils.res index 9c4f164db..f55372c34 100644 --- a/src/screens/APIUtils/APIUtils.res +++ b/src/screens/APIUtils/APIUtils.res @@ -252,7 +252,7 @@ let getURL = ( let sessionExpired = ref(false) let handleLogout = async ( - ~fetchApi as _: ( + ~fetchApi: ( string, ~bodyStr: string=?, ~bodyFormData: option=?, @@ -266,13 +266,17 @@ let handleLogout = async ( ~setIsSidebarExpanded, ~clearRecoilValue, ) => { - // let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ()) - // let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ()) - setAuthStatus(HyperSwitchAuthTypes.LoggedOut) - setIsSidebarExpanded(_ => false) - clearRecoilValue() - LocalStorage.clear() - RescriptReactRouter.push("/login") + try { + setAuthStatus(HyperSwitchAuthTypes.LoggedOut) + setIsSidebarExpanded(_ => false) + clearRecoilValue() + RescriptReactRouter.push("/login") + let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ()) + let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ()) + LocalStorage.clear() + } catch { + | _ => LocalStorage.clear() + } } let responseHandler = async (