Sign-in rules: tests that change their own password send the current one; field labels en/pl; the hook carries a mark

Tests and the late-staff built-site spec that change an account's OWN
password now send currentPassword (the 1.18.0 rule). The Current password
field's label and description are plain { en, pl } (house style checked by
the wording test). The beforeOperation hook carries SIGN_IN_RULES_MARK so
the password-rule hook counts stay what they measure. The injected users
collection carries Payload's lock defaults (50, 1 h).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 11:18:21 +01:00
co-authored by Claude Opus 5.5
parent 52710021ef
commit 420fe40442
8 changed files with 20 additions and 15 deletions
+7 -3
View File
@@ -126,8 +126,11 @@ const signInOriginOk = (req: PayloadRequest, origins: string[]): boolean => {
}
/** `beforeOperation` for a staff collection: the origin rule, the failure count and the current-password rule. */
/** Mark on the sign-in rules' `beforeOperation` hook (tells it apart from the account rules' password hook). */
export const SIGN_IN_RULES_MARK = Symbol.for('iapl.signInRules')
export function buildSignInBeforeOperation(slug: string, rules: Resolved): CollectionBeforeOperationHook {
return async ({ args, operation, req }) => {
const hook: CollectionBeforeOperationHook = async ({ args, operation, req }) => {
if (isLocal(req)) {return args}
const data = ((args as { data?: Record<string, unknown> }).data ?? {})
if (operation === 'login' || operation === 'forgotPassword' || operation === 'resetPassword') {
@@ -141,6 +144,7 @@ export function buildSignInBeforeOperation(slug: string, rules: Resolved): Colle
if (operation === 'update' && rules.confirm) {await confirmOwnChange(slug, args as never, req, rules)}
return args
}
return Object.assign(hook, { [SIGN_IN_RULES_MARK]: true })
}
/** `afterLogin`: the sign-in worked, its place goes back. */
@@ -197,10 +201,10 @@ export function buildCurrentPasswordField(): Field {
const user = (ctx as { user?: { id?: unknown } | null } | undefined)?.user
return Boolean(user && data?.id !== undefined && String(user.id) === String(data.id))
},
description: ({ t }) => serverText({ language: (t as unknown as { i18n?: { language?: string } })?.i18n?.language } as never, 'currentPasswordDescription'),
description: { en: 'Needed only to change your own e-mail address or password.', pl: 'Potrzebne tylko do zmiany własnego adresu e-mail lub hasła.' },
},
hooks: { afterRead: [() => undefined] },
label: ({ t }) => serverText({ language: (t as unknown as { i18n?: { language?: string } })?.i18n?.language } as never, 'currentPasswordLabel'),
label: { en: 'Current password', pl: 'Obecne hasło' },
virtual: true,
} as Field
}
-4
View File
@@ -3,8 +3,6 @@ import { defineTexts } from '../define.js'
/** Admin component texts — two-step verification (2FA). Placeholders use Payload's {{name}} syntax. */
export const securityTexts = defineTexts({
en: {
currentPasswordDescription: 'Needed only to change your own e-mail address or password.',
currentPasswordLabel: 'Current password',
currentPasswordRequired: 'Enter your current password to change your e-mail address or password.',
currentPasswordWrong: 'The current password is not right.',
passwordIsEmail: 'The password cannot be the same as the e-mail address.',
@@ -35,8 +33,6 @@ export const securityTexts = defineTexts({
twoFactorTooManyAttempts: 'Too many codes were tried for this account. Wait {{minutes}} min, then enter the current code from your app.',
},
pl: {
currentPasswordDescription: 'Potrzebne tylko do zmiany własnego adresu e-mail lub hasła.',
currentPasswordLabel: 'Obecne hasło',
currentPasswordRequired: 'Wpisz obecne hasło, aby zmienić adres e-mail lub hasło.',
currentPasswordWrong: 'Obecne hasło jest nieprawidłowe.',
passwordIsEmail: 'Hasło nie może być takie samo jak adres e-mail.',