Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/entryPoints/AuthModule/PreLoginModule/AuthSelect.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let make = (~setSelectedAuthId) => {
let {setAuthStatus, authMethods} = React.useContext(AuthInfoProvider.authStatusContext)
let {fetchAuthMethods} = AuthModuleHooks.useAuthMethods()
let updateDetails = useUpdateMethod()
let {isPasswordEnabled, isMagicLinkEnabled} = AuthModuleHooks.useAuthMethods()
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Success)
let featureFlagValues = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let (logoVariant, iconUrl) = switch Window.env.urlThemeConfig.logoUrl {
| Some(url) => (IconWithURL, Some(url))
| _ => (IconWithText, None)
Expand Down Expand Up @@ -67,6 +69,16 @@ let make = (~setSelectedAuthId) => {
customButtonStyle="!w-full"
onClick={_ => handleTerminateSSO(method.id)->ignore}
/>
| (MAGIC_LINK, #Magic_Link) =>
<RenderIf condition={isMagicLinkEnabled() && !isPasswordEnabled()}>
<Button
text="Continue with Magic Link"
buttonType={Primary}
buttonSize={Large}
customButtonStyle="!w-full"
onClick={_ => handleTerminateSSO(method.id)->ignore}
/>
</RenderIf>
| (_, _) => React.null
}
}
Expand All @@ -89,7 +101,11 @@ let make = (~setSelectedAuthId) => {
->Array.mapWithIndex((authMethod, index) =>
<React.Fragment key={index->Int.toString}>
{authMethod->renderComponentForAuthTypes}
<RenderIf condition={index === 0 && authMethods->Array.length !== 2}>
<RenderIf
condition={authMethods->SSOUtils.checkToRenderOr(
index,
featureFlagValues.email,
) && index != authMethods->Array.length - 1}>
{PreLoginUtils.divider}
</RenderIf>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let make = () => {
open LogicUtils
open PreLoginTypes
open HSwitchUtils
open CommonAuthTypes

let getURL = useGetURL()
let fetchDetails = useGetMethod()
Expand All @@ -14,6 +15,10 @@ let make = () => {
let (acceptedInvites, setAcceptedInvites) = React.useState(_ => [])
let (pendindInvites, setPendingInvites) = React.useState(_ => [])
let handleLogout = useHandleLogout()
let (logoVariant, iconUrl) = switch Window.env.urlThemeConfig.logoUrl {
| Some(url) => (IconWithURL, Some(url))
| _ => (IconWithText, None)
}

let getListOfMerchantIds = async () => {
try {
Expand Down Expand Up @@ -71,7 +76,7 @@ let make = () => {
<div className="h-full w-full flex flex-col gap-4 items-center justify-center p-6">
<div className="bg-white h-35-rem w-200 rounded-2xl">
<div className="p-6 border-b-2">
<img alt="logo-with-text" src={`assets/Dark/hyperswitchLogoIconWithText.svg`} />
<HyperSwitchLogo logoHeight="h-8" theme={Dark} logoVariant iconUrl />
</div>
<div className="p-6 flex flex-col gap-2">
<p className={`${textHeadingClass} text-grey-900`}>
Expand Down
36 changes: 36 additions & 0 deletions src/entryPoints/AuthModule/SSOAuth/SSOUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,39 @@ let ssoDefaultValue = (values: AuthProviderTypes.preLoginType): AuthProviderType
email_token: values.email_token,
}
}

/*
Note: This is to show "OR" between the buttons in AuthSelect page
Theres a special case where we are not rendering component in case of magic link as login with password handles both
*/

/* Determines whether a specific auth method should be rendered in the UI. */
let shouldRenderMethod = (
currentValue: authMethodResponseType,
authMethods: array<authMethodResponseType>,
emailFeatureFlagEnabled: bool,
) => {
switch currentValue.auth_method.\"type" {
| MAGIC_LINK =>
emailFeatureFlagEnabled &&
!(authMethods->Array.some(value => value.auth_method.\"type" == PASSWORD))
| _ => true
}
}

/* This check ensures OR is rendered only when there is another visible auth option ahead. */
let checkToRenderOr = (
authMethods: array<authMethodResponseType>,
index: int,
emailFeatureFlagEnabled: bool,
) => {
authMethods[index]->Option.mapOr(false, currentValue => {
if !shouldRenderMethod(currentValue, authMethods, emailFeatureFlagEnabled) {
false
} else {
authMethods
->Array.sliceToEnd(~start=index + 1)
->Array.some(value => shouldRenderMethod(value, authMethods, emailFeatureFlagEnabled))
}
})
}
10 changes: 8 additions & 2 deletions src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuthScreen.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ let make = (~setAuthStatus) => {
open CommonAuthTypes
let url = RescriptReactRouter.useUrl()
let (_mode, setMode) = React.useState(_ => TestButtonMode)
let {isMagicLinkEnabled, checkAuthMethodExists} = AuthModuleHooks.useAuthMethods()
let {
isMagicLinkEnabled,
checkAuthMethodExists,
isPasswordEnabled,
} = AuthModuleHooks.useAuthMethods()
let {isLiveMode} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let pageViewEvent = MixpanelHook.usePageView()
let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let authInitState = LoginWithPassword
let authInitState =
isMagicLinkEnabled() && !isPasswordEnabled() ? LoginWithEmail : LoginWithPassword

let (authType, setAuthType) = React.useState(_ => authInitState)

React.useEffect(() => {
Expand Down
Loading