diff --git a/app/constants/sso.ts b/app/constants/sso.ts index 73d1c9e3a..4a0df1764 100644 --- a/app/constants/sso.ts +++ b/app/constants/sso.ts @@ -7,6 +7,11 @@ import keyMirror from '@utils/key_mirror'; export const REDIRECT_URL_SCHEME = LocalConfig.AuthUrlScheme; export const REDIRECT_URL_SCHEME_DEV = LocalConfig.AuthUrlSchemeDev; +export const LOGIN_TYPE = { + MAGIC_LINK: 'magic_link', + EMAIL_PASSWORD: '', +} as const; + const constants = keyMirror({ SAML: null, GITLAB: null, @@ -17,6 +22,7 @@ const constants = keyMirror({ export default { ...constants, + ...LOGIN_TYPE, REDIRECT_URL_SCHEME, REDIRECT_URL_SCHEME_DEV, }; diff --git a/app/screens/login/form.tsx b/app/screens/login/form.tsx index 9c670ac24..9287c0b69 100644 --- a/app/screens/login/form.tsx +++ b/app/screens/login/form.tsx @@ -13,6 +13,7 @@ import CompassIcon from '@components/compass_icon'; import FloatingTextInput from '@components/floating_input/floating_text_input_label'; import FormattedText from '@components/formatted_text'; import {FORGOT_PASSWORD, MFA} from '@constants/screens'; +import {LOGIN_TYPE} from '@constants/sso'; import {useAvoidKeyboard} from '@hooks/device'; import {usePreventDoubleTap} from '@hooks/utils'; import {goToScreen, loginAnimationOptions, resetToHome} from '@screens/navigation'; @@ -45,7 +46,7 @@ function getButtonDisabled(loginId: string, password: string, userLoginType: Log return true; } - if (magicLinkEnabled && (userLoginType === 'guest_magic_link' || userLoginType === undefined)) { + if (magicLinkEnabled && (userLoginType === LOGIN_TYPE.MAGIC_LINK || userLoginType === undefined)) { return false; } @@ -248,7 +249,7 @@ const LoginForm = ({ Keyboard.dismiss(); if (magicLinkEnabled && userLoginType === undefined) { const receivedUserLoginType = await checkUserLoginType(); - if (receivedUserLoginType === 'guest_magic_link') { + if (receivedUserLoginType === LOGIN_TYPE.MAGIC_LINK) { setMagicLinkSent(true); } if (isDeactivated) { @@ -310,7 +311,7 @@ const LoginForm = ({ }, [managedConfig?.username]); const onIdInputSubmitting = useCallback(() => { - if (!magicLinkEnabled || (userLoginType !== 'guest_magic_link')) { + if (!magicLinkEnabled || (userLoginType !== LOGIN_TYPE.MAGIC_LINK)) { focusPassword(); return; } @@ -319,7 +320,7 @@ const LoginForm = ({ }, [focusPassword, onLogin, magicLinkEnabled, userLoginType]); const buttonDisabled = getButtonDisabled(loginId, password, userLoginType, isDeactivated, magicLinkEnabled); - const showPasswordInput = !magicLinkEnabled || (userLoginType !== 'guest_magic_link' && userLoginType !== undefined && !isDeactivated); + const showPasswordInput = !magicLinkEnabled || (userLoginType !== LOGIN_TYPE.MAGIC_LINK && userLoginType !== undefined && !isDeactivated); let userInputError = error; if (showPasswordInput) { // error is passed to the password input box, so we use this diff --git a/types/api/users.d.ts b/types/api/users.d.ts index 71be2c752..eb0e7e0c9 100644 --- a/types/api/users.d.ts +++ b/types/api/users.d.ts @@ -163,4 +163,4 @@ type GetUsersOptions = { team_roles?: string; }; -type LoginType = '' | 'guest_magic_link'; +type LoginType = '' | 'magic_link';