diff --git a/frontend/src/entities/user/api.test.ts b/frontend/src/entities/user/api.test.ts index 79623e07..b6a65157 100644 --- a/frontend/src/entities/user/api.test.ts +++ b/frontend/src/entities/user/api.test.ts @@ -55,7 +55,6 @@ describe('createUserApis', () => { await apis.login({ email: 'reader@example.com', password: 'password-123', - code: '123456', }) await apis.loginByCode({ email: 'reader@example.com', code: '123456' }) await apis.refresh('refresh-token') @@ -89,7 +88,6 @@ describe('createUserApis', () => { json: { email: 'reader@example.com', password: 'password-123', - code: '123456', }, }, ], diff --git a/frontend/src/entities/user/index.ts b/frontend/src/entities/user/index.ts index 518f42fb..89b460a8 100644 --- a/frontend/src/entities/user/index.ts +++ b/frontend/src/entities/user/index.ts @@ -25,7 +25,8 @@ export interface UserApis { code: string nickname?: string }): Promise - login(input: { email: string; password: string; code: string }): Promise + /** 密码登录不带验证码;验证码只用于注册、免密登录与重设密码。 */ + login(input: { email: string; password: string }): Promise loginByCode(input: { email: string; code: string }): Promise refresh(refreshToken: string): Promise logout(refreshToken: string): Promise diff --git a/frontend/src/features/account-panel/index.test.tsx b/frontend/src/features/account-panel/index.test.tsx index eedfcb8c..289d7ed2 100644 --- a/frontend/src/features/account-panel/index.test.tsx +++ b/frontend/src/features/account-panel/index.test.tsx @@ -207,31 +207,26 @@ describe('AccountPanel', () => { expect(screen.getByTestId('location').textContent).toBe('/') }) - it('submits password login with a login-purpose code and keeps recovery visibly unavailable', async () => { + it('submits password login without an email code and keeps recovery visibly unavailable', async () => { const { apis } = renderPanel() fireEvent.click(screen.getByRole('tab', { name: '密码登录' })) expect(screen.getByText('忘记密码')).toBeTruthy() expect(screen.getByText('暂未开放')).toBeTruthy() + expect(screen.queryByLabelText('验证码')).toBeNull() + expect(screen.queryByRole('button', { name: '发送验证码' })).toBeNull() + expect(screen.getByText('用邮箱和密码直接登录。')).toBeTruthy() fireEvent.change(screen.getByLabelText('邮箱'), { target: { value: 'reader@example.com' } }) fireEvent.change(screen.getByLabelText('密码'), { target: { value: 'password-123' } }) - fireEvent.change(screen.getByLabelText('验证码'), { target: { value: '123456' } }) - fireEvent.click(screen.getByRole('button', { name: '发送验证码' })) - await waitFor(() => - expect(apis.sendCode).toHaveBeenCalledWith({ - email: 'reader@example.com', - purpose: 'login', - }), - ) fireEvent.submit(screen.getByRole('button', { name: '登录' }).closest('form')!) await waitFor(() => expect(apis.login).toHaveBeenCalledWith({ email: 'reader@example.com', password: 'password-123', - code: '123456', }), ) + expect(apis.sendCode).not.toHaveBeenCalled() }) it('validates registration fields and sends register-purpose codes', async () => { diff --git a/frontend/src/features/account-panel/index.tsx b/frontend/src/features/account-panel/index.tsx index 2d418b1e..9b808626 100644 --- a/frontend/src/features/account-panel/index.tsx +++ b/frontend/src/features/account-panel/index.tsx @@ -32,7 +32,7 @@ const modeCopy: Record< password: { tab: '密码登录', title: '登录 Windup', - description: '使用密码和邮箱验证码确认身份。', + description: '用邮箱和密码直接登录。', submit: '登录', }, register: { @@ -177,7 +177,7 @@ function AccountPanelDialog() { if (mode !== 'code' && (password.length < 8 || password.length > 128)) { return '密码需为 8–128 位' } - if (!CODE_PATTERN.test(code)) return '验证码需为 6 位数字' + if (mode !== 'password' && !CODE_PATTERN.test(code)) return '验证码需为 6 位数字' if (mode === 'register' && nickname.length > 50) return '昵称不能超过 50 个字符' return null } @@ -200,7 +200,7 @@ function AccountPanelDialog() { await session.loginByCode({ email: normalizedEmail, code }) successMessage = '登录成功。如果这是你首次使用该邮箱,我们已为你创建账号。' } else if (mode === 'password') { - await session.login({ email: normalizedEmail, password, code }) + await session.login({ email: normalizedEmail, password }) successMessage = '登录成功,正在继续。' } else { await session.register({ @@ -379,35 +379,37 @@ function AccountPanelDialog() { )} -
- - - setCode(event.target.value)} - disabled={isSubmitting} - className={fieldClass} - placeholder="6 位数字" - /> - - -
+ {mode !== 'password' && ( +
+ + + setCode(event.target.value)} + disabled={isSubmitting} + className={fieldClass} + placeholder="6 位数字" + /> + + +
+ )} {mode === 'code' && (

diff --git a/frontend/src/features/auth-session/index.test.tsx b/frontend/src/features/auth-session/index.test.tsx index 76d4ddd3..f4672add 100644 --- a/frontend/src/features/auth-session/index.test.tsx +++ b/frontend/src/features/auth-session/index.test.tsx @@ -144,7 +144,6 @@ describe('AuthSessionProvider', () => { await session().login({ email: 'reader@example.com', password: 'password-123', - code: '123456', }) } else { await session().loginByCode({ email: 'reader@example.com', code: '123456' })