|
|
@@ -9,6 +9,7 @@ import { useRouter } from 'next/router';
|
|
|
import ReactCardFlip from 'react-card-flip';
|
|
|
|
|
|
import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
+import { useTWithOpt } from '~/client/util/t-with-opt';
|
|
|
import type { IExternalAccountLoginError } from '~/interfaces/errors/external-account-login-error';
|
|
|
import { LoginErrorCode } from '~/interfaces/errors/login-error';
|
|
|
import type { IErrorV3 } from '~/interfaces/errors/v3-error';
|
|
|
@@ -21,6 +22,7 @@ import { ExternalAuthButton } from './ExternalAuthButton';
|
|
|
|
|
|
import styles from './LoginForm.module.scss';
|
|
|
|
|
|
+
|
|
|
const moduleClass = styles['login-form'];
|
|
|
|
|
|
|
|
|
@@ -38,6 +40,7 @@ type LoginFormProps = {
|
|
|
enabledExternalAuthType?: IExternalAuthProviderType[],
|
|
|
isMailerSetup?: boolean,
|
|
|
externalAccountLoginError?: IExternalAccountLoginError,
|
|
|
+ minPasswordLength: number,
|
|
|
}
|
|
|
export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
const { t } = useTranslation();
|
|
|
@@ -46,8 +49,9 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
|
|
|
const {
|
|
|
isLocalStrategySetup, isLdapStrategySetup, isLdapSetupFailed, isPasswordResetEnabled,
|
|
|
- isEmailAuthenticationEnabled, registrationMode, registrationWhitelist, isMailerSetup, enabledExternalAuthType,
|
|
|
+ isEmailAuthenticationEnabled, registrationMode, registrationWhitelist, isMailerSetup, enabledExternalAuthType, minPasswordLength,
|
|
|
} = props;
|
|
|
+
|
|
|
const isLocalOrLdapStrategiesEnabled = isLocalStrategySetup || isLdapStrategySetup;
|
|
|
const isSomeExternalAuthEnabled = enabledExternalAuthType != null && enabledExternalAuthType.length > 0;
|
|
|
|
|
|
@@ -71,6 +75,8 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
|
|
|
const isRegistrationEnabled = isLocalStrategySetup && registrationMode !== RegistrationMode.CLOSED;
|
|
|
|
|
|
+ const tWithOpt = useTWithOpt();
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
const { hash } = window.location;
|
|
|
if (hash === '#register') {
|
|
|
@@ -78,13 +84,6 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
}
|
|
|
}, []);
|
|
|
|
|
|
- const tWithOpt = useCallback((key: string, opt?: any) => {
|
|
|
- if (typeof opt === 'object') {
|
|
|
- return t(key, opt).toString();
|
|
|
- }
|
|
|
- return t(key);
|
|
|
- }, [t]);
|
|
|
-
|
|
|
const resetLoginErrors = useCallback(() => {
|
|
|
if (loginErrors.length === 0) return;
|
|
|
setLoginErrors([]);
|
|
|
@@ -253,15 +252,8 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
</>
|
|
|
);
|
|
|
}, [
|
|
|
- props,
|
|
|
- separateErrorsBasedOnErrorCode,
|
|
|
- loginErrors,
|
|
|
- generateDangerouslySetErrors,
|
|
|
- generateSafelySetErrors,
|
|
|
- isLdapSetupFailed,
|
|
|
- t,
|
|
|
- handleLoginWithLocalSubmit,
|
|
|
- isLoading,
|
|
|
+ props, separateErrorsBasedOnErrorCode, loginErrors, generateDangerouslySetErrors, generateSafelySetErrors,
|
|
|
+ isLdapSetupFailed, t, handleLoginWithLocalSubmit, isLoading,
|
|
|
]);
|
|
|
|
|
|
|
|
|
@@ -360,7 +352,7 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
<p className="alert alert-danger">
|
|
|
{registerErrors.map(err => (
|
|
|
<span>
|
|
|
- {t(err.message)}<br />
|
|
|
+ {tWithOpt(err.message, err.args)}<br />
|
|
|
</span>
|
|
|
))}
|
|
|
</p>
|
|
|
@@ -461,6 +453,7 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
placeholder={t('Password')}
|
|
|
name="password"
|
|
|
required
|
|
|
+ minLength={minPasswordLength}
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -501,8 +494,8 @@ export const LoginForm = (props: LoginFormProps): JSX.Element => {
|
|
|
</React.Fragment>
|
|
|
);
|
|
|
}, [
|
|
|
- t, isEmailAuthenticationEnabled, registrationMode, isMailerSetup, registerErrors, isSuccessToRagistration,
|
|
|
- emailForRegistrationOrder, props.username, props.name, props.email, registrationWhitelist, switchForm, handleRegisterFormSubmit, isLoading,
|
|
|
+ t, isEmailAuthenticationEnabled, registrationMode, isMailerSetup, registerErrors, isSuccessToRagistration, emailForRegistrationOrder,
|
|
|
+ props.username, props.name, props.email, registrationWhitelist, minPasswordLength, isLoading, switchForm, tWithOpt, handleRegisterFormSubmit,
|
|
|
]);
|
|
|
|
|
|
if (registrationMode === RegistrationMode.RESTRICTED && isSuccessToRagistration && !isEmailAuthenticationEnabled) {
|