fix(auth): ask for the 5-digit code the API sends

The API sends a 5-digit sign-in code, but the code step drew six cells and
its validation wanted six digits, so nobody could sign in or register. The
admin panel keeps its 6-digit code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-11-05 19:01:42 +04:00
parent 69a76446d2
commit 5b8b8f4cd4
4 changed files with 10 additions and 8 deletions

View File

@ -11,12 +11,13 @@ import type { FormEvent } from 'react';
import { Controller } from 'react-hook-form'; import { Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { CODE_RULES } from '../../../../../../features/auth';
import { formatMobile, translateMessage } from '../../../../../../shared/utils'; import { formatMobile, translateMessage } from '../../../../../../shared/utils';
import { SupportEntry } from '../../../../organisms/support-entry'; import { SupportEntry } from '../../../../organisms/support-entry';
import type { CodeStepProps } from './types'; import type { CodeStepProps } from './types';
/** /**
* The 6-digit code step of login and registration: the number it went to, the cells, the resend * The 5-digit code step of login and registration: the number it went to, the cells, the resend
* wait and the submit button under them. Blocked, the cells and the button rest and the wait * wait and the submit button under them. Blocked, the cells and the button rest and the wait
* counts to the moment a new code may be asked for; «ویرایش شماره» stays live. Limited (too many * counts to the moment a new code may be asked for; «ویرایش شماره» stays live. Limited (too many
* codes in an hour), only the wait is amber: the last code can still be typed. * codes in an hour), only the wait is amber: the last code can still be typed.
@ -78,6 +79,7 @@ export function CodeStep({
<OtpInput <OtpInput
// A new key empties the cells' own state and focuses the first cell again. // A new key empties the cells' own state and focuses the first cell again.
key={attempt} key={attempt}
length={CODE_RULES.length}
name={field.name} name={field.name}
value={field.value} value={field.value}
onChange={(value: string) => { onChange={(value: string) => {

View File

@ -14,12 +14,12 @@ export const AUTH_EVENTS = {
export const AUTH_PURPOSES = ['login', 'register'] as const; export const AUTH_PURPOSES = ['login', 'register'] as const;
/** /**
* The code rules the pages show. The server owns them (a code lives 10 minutes, the third wrong * The code rules the pages show. The server owns them (5 digits, a code lives 2 minutes, the third wrong
* code blocks the number for 10 minutes, at most 5 codes per number in an hour); the 2-minute * code blocks the number for 10 minutes, at most 5 codes per number in an hour); the 2-minute
* resend wait is the product's, longer than the server's 60-second cooldown. * resend opens when the code runs out.
*/ */
export const CODE_RULES = { export const CODE_RULES = {
length: 6, length: 5,
resendWaitSeconds: 120, resendWaitSeconds: 120,
maxMisses: 3, maxMisses: 3,
blockSeconds: 600, blockSeconds: 600,

View File

@ -44,8 +44,8 @@
}, },
"code": { "code": {
"title": "کد تأیید را وارد کنید", "title": "کد تأیید را وارد کنید",
"description": "کد 6 رقمی ارسال‌شده به {{phone}} را وارد کنید.", "description": "کد 5 رقمی ارسال‌شده به {{phone}} را وارد کنید.",
"label": "کد تأیید 6 رقمی", "label": "کد تأیید 5 رقمی",
"edit-phone": "ویرایش شماره", "edit-phone": "ویرایش شماره",
"wrong": "کد وارد‌شده اشتباه است. لطفاً دوباره تلاش کنید.", "wrong": "کد وارد‌شده اشتباه است. لطفاً دوباره تلاش کنید.",
"wrong-last": "کد وارد‌شده اشتباه است. یک تلاش دیگر باقی مانده است.", "wrong-last": "کد وارد‌شده اشتباه است. یک تلاش دیگر باقی مانده است.",
@ -297,7 +297,7 @@
}, },
"validation": { "validation": {
"phone-invalid": "شماره موبایل وارد‌شده معتبر نیست.", "phone-invalid": "شماره موبایل وارد‌شده معتبر نیست.",
"code-length": "کد 6 رقمی را کامل وارد کنید.", "code-length": "کد 5 رقمی را کامل وارد کنید.",
"role-required": "نوع حساب را انتخاب کنید.", "role-required": "نوع حساب را انتخاب کنید.",
"required": "این فیلد الزامی است.", "required": "این فیلد الزامی است.",
"first-name-persian": "لطفاً نام را به فارسی وارد کنید.", "first-name-persian": "لطفاً نام را به فارسی وارد کنید.",

View File

@ -22,7 +22,7 @@ export const ID_CARD_SIDES = [
export const ACCOUNT_TYPES = ['investor', 'creator'] as const; export const ACCOUNT_TYPES = ['investor', 'creator'] as const;
export const CODE_PATTERN = /^\d{6}$/; export const CODE_PATTERN = /^\d{5}$/;
/** The server's creator profile rules (`CREATOR_PROFILE_LIMITS`), so forms reject what the API would. */ /** The server's creator profile rules (`CREATOR_PROFILE_LIMITS`), so forms reject what the API would. */
export const PROFILE_LIMITS = { export const PROFILE_LIMITS = {