Skip to content

Commit

Permalink
refactor: totp flow file rename (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 authored Jun 13, 2024
1 parent b2f520d commit a762c91
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/context/AuthInfoProvider.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let make = (~children) => {
| TotpAuth(totpInfo) =>
if !(totpInfo.token->LogicUtils.isEmptyString) {
setAuth(_ => newAuthStatus)
TotpUtils.setTotpAuthResToStorage(totpInfo)
TwoFaUtils.setTotpAuthResToStorage(totpInfo)
} else {
setAuth(_ => LoggedOut)
CommonAuthUtils.clearLocalStorage()
Expand All @@ -51,7 +51,7 @@ let make = (~children) => {
| PreLogin(preLoginInfo) =>
if !(preLoginInfo.token->LogicUtils.isEmptyString) {
setAuth(_ => newAuthStatus)
TotpUtils.setTotpAuthResToStorage(preLoginInfo)
TwoFaUtils.setTotpAuthResToStorage(preLoginInfo)
} else {
setAuth(_ => LoggedOut)
CommonAuthUtils.clearLocalStorage()
Expand Down
2 changes: 1 addition & 1 deletion src/entryPoints/AuthModule/AuthProviderTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ type preLoginType = {
token_type: string,
email_token: option<string>,
}
type authType = BasicAuth(BasicAuthTypes.basicAuthInfo) | TotpAuth(TotpTypes.totpAuthInfo)
type authType = BasicAuth(BasicAuthTypes.basicAuthInfo) | TotpAuth(TwoFaTypes.twoFaAuthInfo)

type authStatus = LoggedOut | PreLogin(preLoginType) | LoggedIn(authType) | CheckingAuthStatus
8 changes: 4 additions & 4 deletions src/entryPoints/AuthModule/AuthWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let make = (~children) => {
let {authStatus, setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext)

let authLogic = () => {
open TotpUtils
open TwoFaUtils
open LogicUtils
let preLoginInfo = getTotpPreLoginInfoFromStorage()
let loggedInInfo = getTotpAuthInfoFromStrorage()
Expand All @@ -77,7 +77,7 @@ let make = (~children) => {
switch tokenFromUrl {
| Some(token) => {
let response = await updateDetails(url, token->generateBodyForEmailRedirection, Post, ())
setAuthStatus(PreLogin(TotpUtils.getPreLoginInfo(response, ~email_token=Some(token))))
setAuthStatus(PreLogin(TwoFaUtils.getPreLoginInfo(response, ~email_token=Some(token))))
}
| None => setAuthStatus(LoggedOut)
}
Expand Down Expand Up @@ -105,9 +105,9 @@ let make = (~children) => {
{switch authStatus {
| LoggedOut =>
<AuthHeaderWrapper>
<TotpAuthScreen setAuthStatus />
<TwoFaAuthScreen setAuthStatus />
</AuthHeaderWrapper>
| PreLogin(_) => <TotpDecisionScreen />
| PreLogin(_) => <TwoFaDecisionScreen />
| LoggedIn(_token) => children
| CheckingAuthStatus => <PageLoaderWrapper.ScreenLoader />
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let make = () => {

let acceptInviteFromEmailWithSPT = async body => {
try {
open TotpUtils
open TwoFaUtils

let url = getURL(
~entityName=USERS,
Expand All @@ -31,7 +31,7 @@ let make = () => {

React.useEffect0(() => {
open CommonAuthUtils
open TotpUtils
open TwoFaUtils
open HSwitchGlobalVars
RescriptReactRouter.replace(appendDashboardPath(~url="/accept_invite_from_email"))
let emailToken = authStatus->getEmailToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let make = () => {

let verifyEmailWithSPT = async body => {
try {
open TotpUtils
open TwoFaUtils
let url = getURL(
~entityName=USERS,
~methodType=Post,
Expand All @@ -31,7 +31,7 @@ let make = () => {

React.useEffect0(() => {
open CommonAuthUtils
open TotpUtils
open TwoFaUtils
open HSwitchGlobalVars

RescriptReactRouter.replace(appendDashboardPath(~url="/accept_invite_from_email"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make = () => {
})

let onClickLoginToDashboard = async () => {
open TotpUtils
open TwoFaUtils
try {
let url = getURL(~entityName=USERS, ~userType=#ACCEPT_INVITE_TOKEN_ONLY, ~methodType=Post, ())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~setTwoFaPageState, ~onClickDownload, ~setShowNewQR) => {
let errorCode = err->safeParse->getDictFromJsonObject->getString("code", "")

if errorCode->CommonAuthUtils.errorSubCodeMapper === UR_38 {
setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR)
setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_QR)
setShowNewQR(prev => !prev)
} else {
showToast(~message="Something went wrong", ~toastType=ToastError, ())
Expand Down Expand Up @@ -76,7 +76,7 @@ let make = (~setTwoFaPageState, ~onClickDownload, ~setShowNewQR) => {
buttonType={Primary}
buttonSize={Small}
onClick={_ => {
TotpUtils.downloadRecoveryCodes(~recoveryCodes)
TwoFaUtils.downloadRecoveryCodes(~recoveryCodes)
onClickDownload(~skip_2fa=false)->ignore
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ let make = (~flowType) => {
}

let confirmButtonAction = async password => {
open TotpTypes
open TotpUtils
open TwoFaTypes
open TwoFaUtils
try {
switch flowType {
| FORCE_SET_PASSWORD => await rotatePassword(password)
Expand Down Expand Up @@ -131,7 +131,7 @@ let make = (~flowType) => {
key="auth"
initialValues
validate={values =>
TotpUtils.validateTotpForm(values, ["create_password", "comfirm_password"])}
TwoFaUtils.validateTotpForm(values, ["create_password", "comfirm_password"])}
onSubmit>
<div className="flex flex-col gap-6">
<h1 id="card-header" className="font-semibold text-xl md:text-2xl">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module EnterAccessCode = {
{"Didn't get a code? "->React.string}
<span
className="cursor-pointer underline underline-offset-2 text-blue-600"
onClick={_ => setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR)}>
onClick={_ => setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_QR)}>
{"Use totp instead"->React.string}
</span>
</p>
Expand Down Expand Up @@ -106,7 +106,7 @@ module ConfigureTotpScreen = {
~setTwoFaPageState,
~terminateTwoFactorAuth,
) => {
open TotpTypes
open TwoFaTypes

let verifyTotpLogic = TotpHooks.useVerifyTotp()

Expand All @@ -128,7 +128,7 @@ module ConfigureTotpScreen = {
if twoFaStatus === TWO_FA_SET {
terminateTwoFactorAuth(~skip_2fa=false)->ignore
} else {
setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_RC)
setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_RC)
}
} else {
showToast(~message="OTP field cannot be empty!", ~toastType=ToastError, ())
Expand Down Expand Up @@ -226,7 +226,7 @@ module ConfigureTotpScreen = {
@react.component
let make = () => {
open HSwitchUtils
open TotpTypes
open TwoFaTypes

let getURL = APIUtils.useGetURL()
let showToast = ToastState.useShowToast()
Expand All @@ -236,7 +236,7 @@ let make = () => {
let (isQrVisible, setIsQrVisible) = React.useState(_ => false)
let (totpUrl, setTotpUrl) = React.useState(_ => "")
let (twoFaStatus, setTwoFaStatus) = React.useState(_ => TWO_FA_NOT_SET)
let (twoFaPageState, setTwoFaPageState) = React.useState(_ => TotpTypes.TOTP_SHOW_QR)
let (twoFaPageState, setTwoFaPageState) = React.useState(_ => TOTP_SHOW_QR)
let (showNewQR, setShowNewQR) = React.useState(_ => false)

let delayTimer = () => {
Expand All @@ -256,7 +256,7 @@ let make = () => {
let terminateTwoFactorAuth = async (~skip_2fa) => {
open LogicUtils
try {
open TotpUtils
open TwoFaUtils

let url = `${getURL(
~entityName=USERS,
Expand All @@ -276,7 +276,7 @@ let make = () => {
errorCode->CommonAuthUtils.errorSubCodeMapper === UR_40 ||
errorCode->CommonAuthUtils.errorSubCodeMapper === UR_41
) {
setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR)
setTwoFaPageState(_ => TOTP_SHOW_QR)
showToast(~message="Failed to complete 2fa!", ~toastType=ToastError, ())
setShowNewQR(prev => !prev)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let make = () => {
let response = await fetchDetails(url)
let dict = response->getDictFromJsonObject
dict->setOptionString("token", token)
let info = TotpUtils.getTotpAuthInfo(dict->JSON.Encode.object)
let info = TwoFaUtils.getTotpAuthInfo(dict->JSON.Encode.object)
setAuthStatus(LoggedIn(TotpAuth(info)))
setIsSidebarDetails("isPinned", false->JSON.Encode.bool)
setScreenState(_ => PageLoaderWrapper.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let make = (~setAuthStatus, ~authType, ~setAuthType) => {
open CommonAuthForm
open HSwitchGlobalVars
open LogicUtils
open TotpUtils
open TwoFaUtils
open AuthProviderTypes
let getURL = useGetURL()
let url = RescriptReactRouter.useUrl()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ let make = (~setAuthStatus) => {
None
}, [authType])

<TotpAuth setAuthStatus authType setAuthType />
<TwoFaAuth setAuthStatus authType setAuthType />
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let make = () => {
let {authStatus, setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext)

let flowType = switch authStatus {
| PreLogin(info) => info.token_type->TotpUtils.flowTypeStrToVariantMapperForNewFlow
| PreLogin(info) => info.token_type->TwoFaUtils.flowTypeStrToVariantMapperForNewFlow
| _ => ERROR
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type totpFlowType =
type twoFaFlowType =
| MERCHANT_SELECT
| TOTP
| FORCE_SET_PASSWORD
Expand All @@ -9,7 +9,7 @@ type totpFlowType =
| USER_INFO
| ERROR

type totpAuthInfo = {
type twoFaAuthInfo = {
token: string,
merchant_id: string,
name: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open TotpTypes
open TwoFaTypes

let flowTypeStrToVariantMapper = val => {
switch val {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ module RegenerateRecoveryCodes = {
buttonType={Primary}
buttonSize={Small}
onClick={_ => {
TotpUtils.downloadRecoveryCodes(~recoveryCodes)
TwoFaUtils.downloadRecoveryCodes(~recoveryCodes)
showToast(
~message="Successfully regenerated new recovery codes !",
~toastType=ToastSuccess,
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SwitchMerchant/SwitchMerchant.res
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ let make = (~userRole, ~isAddMerchantEnabled=false) => {
if featureFlagDetails.totp {
let responseDict = res->getDictFromJsonObject
setAuthStatus(
LoggedIn(TotpAuth(TotpUtils.getTotpAuthInfo(responseDict->JSON.Encode.object))),
LoggedIn(TotpAuth(TwoFaUtils.getTotpAuthInfo(responseDict->JSON.Encode.object))),
)
} else {
setAuthStatus(LoggedIn(BasicAuth(res->BasicAuthUtils.getBasicAuthInfo)))
Expand Down

0 comments on commit a762c91

Please sign in to comment.