Skip to content

Commit

Permalink
fix: handle logout (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanikabansal-juspay authored Nov 12, 2024
1 parent abddad9 commit 469e272
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/entryPoints/AuthModule/Common/CommonInviteScreen.res
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -78,7 +78,7 @@ let make = (~merchantData, ~acceptInviteOnClick, ~onClickLoginToDashboard) => {
{"Log in with a different account?"->React.string}
<p
className="underline cursor-pointer underline-offset-2 hover:text-blue-700"
onClick={_ => setAuthStatus(LoggedOut)}>
onClick={_ => handleLogout()->ignore}>
{"Click here to log out."->React.string}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -122,7 +123,7 @@ let make = () => {
{"Log in with a different account?"->React.string}
<p
className="underline cursor-pointer underline-offset-2 hover:text-blue-700"
onClick={_ => setAuthStatus(LoggedOut)}>
onClick={_ => handleLogout()->ignore}>
{"Click here to log out."->React.string}
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/entryPoints/AuthModule/TwoFaAuth/TotpSetup.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -362,7 +362,7 @@ let make = (~setTwoFaPageState, ~twoFaPageState, ~errorHandling, ~isSkippable) =
{"Log in with a different account?"->React.string}
<p
className="underline cursor-pointer underline-offset-2 hover:text-blue-700"
onClick={_ => setAuthStatus(LoggedOut)}>
onClick={_ => handleLogout()->ignore}>
{"Click here to log out."->React.string}
</p>
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/entryPoints/AuthModule/TwoFaAuth/TwoFaLanding.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
<div
Expand Down Expand Up @@ -62,7 +61,7 @@ module AttemptsExpiredComponent = {
{"Log in with a different account?"->React.string}
<p
className="underline cursor-pointer underline-offset-2 hover:text-blue-700"
onClick={_ => setAuthStatus(LoggedOut)}>
onClick={_ => handleLogout()->ignore}>
{"Click here to log out."->React.string}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand All @@ -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) => {
Expand Down

0 comments on commit 469e272

Please sign in to comment.