From 469e272d56b4deecd18653f0abb0bbac38ccdfe7 Mon Sep 17 00:00:00 2001 From: Kanika Bansal Date: Tue, 12 Nov 2024 10:31:13 +0530 Subject: [PATCH] fix: handle logout (#1710) --- src/entryPoints/AuthModule/Common/CommonInviteScreen.res | 4 ++-- .../AuthModule/PreLoginModule/ListInvitationScreen.res | 3 ++- src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res | 4 ++-- src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res | 5 ++--- .../Settings/HSwitchProfile/HSwitchProfileSettings.res | 6 ++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/entryPoints/AuthModule/Common/CommonInviteScreen.res b/src/entryPoints/AuthModule/Common/CommonInviteScreen.res index 0fde0100e..7faad2b31 100644 --- a/src/entryPoints/AuthModule/Common/CommonInviteScreen.res +++ b/src/entryPoints/AuthModule/Common/CommonInviteScreen.res @@ -5,7 +5,7 @@ let make = (~merchantData, ~acceptInviteOnClick, ~onClickLoginToDashboard) => { let textHeadingClass = getTextClass((H2, Optional)) let textSubHeadingClass = getTextClass((P1, Regular)) - let {setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) + let handleLogout = APIUtils.useHandleLogout() let isAtleastOneAccept = React.useMemo(() => { merchantData ->Array.find(ele => ele->getDictFromJsonObject->getBool("is_active", false)) @@ -78,7 +78,7 @@ let make = (~merchantData, ~acceptInviteOnClick, ~onClickLoginToDashboard) => { {"Log in with a different account?"->React.string}

setAuthStatus(LoggedOut)}> + onClick={_ => handleLogout()->ignore}> {"Click here to log out."->React.string}

diff --git a/src/entryPoints/AuthModule/PreLoginModule/ListInvitationScreen.res b/src/entryPoints/AuthModule/PreLoginModule/ListInvitationScreen.res index d781993ec..af61260fb 100644 --- a/src/entryPoints/AuthModule/PreLoginModule/ListInvitationScreen.res +++ b/src/entryPoints/AuthModule/PreLoginModule/ListInvitationScreen.res @@ -13,6 +13,7 @@ let make = () => { let {setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) let (acceptedInvites, setAcceptedInvites) = React.useState(_ => []) let (pendindInvites, setPendingInvites) = React.useState(_ => []) + let handleLogout = useHandleLogout() let getListOfMerchantIds = async () => { try { @@ -122,7 +123,7 @@ let make = () => { {"Log in with a different account?"->React.string}

setAuthStatus(LoggedOut)}> + onClick={_ => handleLogout()->ignore}> {"Click here to log out."->React.string}

diff --git a/src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res b/src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res index 34039bf83..3495b88dc 100644 --- a/src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res @@ -246,7 +246,7 @@ let make = (~setTwoFaPageState, ~twoFaPageState, ~errorHandling, ~isSkippable) = let getURL = APIUtils.useGetURL() let showToast = ToastState.useShowToast() let fetchDetails = APIUtils.useGetMethod() - + let handleLogout = APIUtils.useHandleLogout() let {setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) let (isQrVisible, setIsQrVisible) = React.useState(_ => false) @@ -362,7 +362,7 @@ let make = (~setTwoFaPageState, ~twoFaPageState, ~errorHandling, ~isSkippable) = {"Log in with a different account?"->React.string}

setAuthStatus(LoggedOut)}> + onClick={_ => handleLogout()->ignore}> {"Click here to log out."->React.string}

diff --git a/src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res index c48ee9a24..5861ba2c2 100644 --- a/src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res @@ -5,8 +5,7 @@ module AttemptsExpiredComponent = { let make = (~expiredType, ~setTwoFaPageState, ~setTwoFaStatus) => { open TwoFaTypes open HSwitchUtils - let {setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) - + let handleLogout = APIUtils.useHandleLogout() let expiredComponent = switch expiredType { | TOTP_ATTEMPTS_EXPIRED =>
React.string}

setAuthStatus(LoggedOut)}> + onClick={_ => handleLogout()->ignore}> {"Click here to log out."->React.string}

diff --git a/src/screens/Settings/HSwitchProfile/HSwitchProfileSettings.res b/src/screens/Settings/HSwitchProfile/HSwitchProfileSettings.res index 158bdc3f0..2c1219a5e 100644 --- a/src/screens/Settings/HSwitchProfile/HSwitchProfileSettings.res +++ b/src/screens/Settings/HSwitchProfile/HSwitchProfileSettings.res @@ -13,8 +13,7 @@ module ChangePasswordModal = { let getURL = useGetURL() let showToast = ToastState.useShowToast() let updateDetails = useUpdateMethod(~showErrorToast=false) - let fetchApi = AuthHooks.useApiFetcher() - let {xFeatureRoute} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom + let handleLogout = useHandleLogout() let onSubmit = async (values, _) => { let valuesDict = values->getDictFromJsonObject let oldPassword = getString(valuesDict, "old_password", "") @@ -28,8 +27,7 @@ module ChangePasswordModal = { ]->getJsonFromArrayOfJson let _ = await updateDetails(url, body, Post) showToast(~message="Password Changed Successfully", ~toastType=ToastSuccess) - let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT) - let _ = fetchApi(logoutUrl, ~method_=Post, ~xFeatureRoute) + let _ = handleLogout()->ignore setShowModal(_ => false) } catch { | Exn.Error(e) => {