Sign-in look: the client's logo or the site's name on a dark panel beside the form (whiteLabel.signIn)

On by default with whiteLabel. The login screen and the 2FA screens get the look through AdminLogo and
SafeTotpView, which every site already has in its import map: an upgrade needs no edit. allScreens adds one
provider (SignInLook) for forgot / reset password, first user and logout; a production start leaves it out
when the import map on disk lacks it. Logo and name come from Site settings: no new field, no migration.
Language links through GET /api/ipal/admin-language (Payload's own cookie, back to an admin path only).
Options: accent, logoMadeFor, languages, svgLogo; whiteLabel.brandAccess 'admin'. The 2FA code boxes get
names for screen readers. Reference site and starter: allScreens on. Docs, agent guide, skills, tests.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:35:33 +01:00
co-authored by Claude Fable 5.2
parent e821d52d19
commit b6c91a3a11
38 changed files with 1792 additions and 21 deletions
@@ -0,0 +1,22 @@
'use client'
import { useEffect } from 'react'
/**
* Names for the boxes of the 2FA code. The package draws one text box per digit without a label, so a screen
* reader announces six unnamed fields. After the page is live each box gets `aria-label` ("Digit 2 of 6") and
* the numeric keyboard on a phone. Attributes only: no value, handler or focus is touched, and a box that
* already has a name keeps it. Rendered by `SafeTotpView` together with the sign-in look.
*/
export function CodeInputNames({ label }: { label: string }) {
useEffect(() => {
const boxes = document.querySelectorAll<HTMLInputElement>('.template-minimal form input[type="text"][maxlength="1"]')
boxes.forEach((box, index) => {
if (!box.hasAttribute('aria-label') && !box.hasAttribute('aria-labelledby')) {
box.setAttribute('aria-label', label.replace('%n', String(index + 1)).replace('%t', String(boxes.length)))
}
if (!box.hasAttribute('inputmode')) {box.setAttribute('inputmode', 'numeric')}
})
}, [label])
return null
}
+35 -2
View File
@@ -4,9 +4,21 @@ import type React from 'react'
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent'
import { getFromImportMap } from 'payload/shared'
import type { SignInLookProps } from '../../branding/signIn/brand.js'
import { iaplT } from '../../admin-i18n/t.js'
import { securityTexts } from '../../admin-i18n/texts/security.js'
import { signInProviderActive } from '../../branding/signIn/brand.js'
import { SignInPanel } from '../../branding/signIn/SignInPanel.js'
import { CodeInputNames } from './CodeInputNames.js'
import { safeAdminBack, type SafeBackRule, type TotpViewComponent, totpViewImportKey } from './safeBack.js'
export type SafeTotpViewProps = {
/**
* `whiteLabel.signIn`, set by the plugin: the sign-in panel is printed in front of the 2FA screen when the
* provider (`SignInLook`) does not print it. Not set: the screen as the package draws it.
*/
iaplSignIn?: SignInLookProps
/** `twoFactor.safeBack` as a function: replaces the default rule. */
ipalSafeBack?: SafeBackRule
/** `clientProps` of the view's own registration; passed on to it. */
@@ -42,7 +54,7 @@ const CLIENT_PROPS = ['browseByFolderSlugs', 'clientConfig', 'collectionSlug', '
* `admin.dependencies`.
*/
export function SafeTotpView(props: SafeTotpViewProps): React.ReactNode {
const { ipalSafeBack, ipalTotpClientProps, ipalTotpView, ...rest } = props
const { iaplSignIn, ipalSafeBack, ipalTotpClientProps, ipalTotpView, ...rest } = props
const config = props.initPageResult?.req?.payload?.config ?? props.payload?.config
const query = (props.searchParams ?? {}) as Record<string, unknown>
const back = (ipalSafeBack ?? safeAdminBack)(typeof query.back === 'string' ? query.back : undefined, {
@@ -61,10 +73,31 @@ export function SafeTotpView(props: SafeTotpViewProps): React.ReactNode {
for (const key of CLIENT_PROPS) {
if (key in rest) {clientProps[key] = (rest as Record<string, unknown>)[key]}
}
return RenderServerComponent({
const view = RenderServerComponent({
clientProps,
Component: ipalTotpView,
importMap: props.importMap,
serverProps: { ...rest, searchParams },
})
const req = props.initPageResult?.req
const payload = req?.payload ?? props.payload
// The look only: the panel is a sibling in front of the screen, the screen itself is rendered as above.
if (!iaplSignIn) {return view}
const i18n = (req?.i18n ?? props.i18n) as { t: (key: never, vars?: Record<string, unknown>) => string } | undefined
const digit = i18n ? iaplT(i18n.t, 'twoFactorCodeDigit', { n: '%n', total: '%t' }) : securityTexts.en.twoFactorCodeDigit.replace('{{n}}', '%n').replace('{{total}}', '%t')
return (
<>
{signInProviderActive(payload) ? null : (
<SignInPanel
i18n={i18n as never}
locale={(props.initPageResult?.locale ?? props.locale) as never}
look={iaplSignIn}
payload={payload}
user={(req?.user ?? props.user) as never}
/>
)}
{view}
<CodeInputNames label={digit} />
</>
)
}