From 2886c89d8a5628ed2390e43d6cad19ca25f5b411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Thu, 29 Oct 2026 15:34:01 +0100 Subject: [PATCH] 2FA screens: plain en/pl texts and tab title; CookieButton moves up above the footer - TOTP_TEXTS (admin-ux.md wording) merged over @clocklimited/payload-2fa's long, informal texts; the project's i18n.translations still win; twoFactor.texts: false keeps the package's. Setup/verify screens titled "Two-step verification" / "Weryfikacja dwuetapowa" instead of "Payload". - CookieButton: position via --ipal-cookie-button-offset / -inset and --ipal-z-header; lifts above the footer (avoid, default COOKIE_BUTTON_AVOID) while it is on screen; side prop; className still replaces the look. - dev: a footer in the frontend layout to check the button against. Co-Authored-By: Claude Opus 5.5 --- dev/app/(frontend)/[locale]/layout.tsx | 6 ++ docs/agent/skills/ipal-reference/SKILL.md | 1 + .../skills/ipal-reference/resources/api.md | 4 +- docs/consent.md | 7 +- docs/dev/admin-ux.md | 1 + docs/i18n.md | 5 +- docs/security.md | 16 ++++ src/exports/client.ts | 4 +- src/index.ts | 3 +- src/modules/consent/CookieButton.tsx | 74 +++++++++++++++-- src/modules/consent/client.ts | 3 +- src/modules/security/totp/totpTexts.ts | 51 ++++++++++++ src/plugin.ts | 31 +++++++ src/types.ts | 6 ++ test/totpTextsAndCookieButton.test.ts | 80 +++++++++++++++++++ 15 files changed, 281 insertions(+), 11 deletions(-) create mode 100644 src/modules/security/totp/totpTexts.ts create mode 100644 test/totpTextsAndCookieButton.test.ts diff --git a/dev/app/(frontend)/[locale]/layout.tsx b/dev/app/(frontend)/[locale]/layout.tsx index 26537f5..3d608c7 100644 --- a/dev/app/(frontend)/[locale]/layout.tsx +++ b/dev/app/(frontend)/[locale]/layout.tsx @@ -15,6 +15,12 @@ export default async function LocaleLayout({ children, params }: Props) { } logEndpoint="/api/ipal/consent" shell={await getSiteShell(locale)} stats={{ locale }}>
{children}
+ {/* A footer with links in the bottom-left corner: CookieButton must not cover them. */} +
diff --git a/docs/agent/skills/ipal-reference/SKILL.md b/docs/agent/skills/ipal-reference/SKILL.md index 0a9bf7c..92afdc5 100644 --- a/docs/agent/skills/ipal-reference/SKILL.md +++ b/docs/agent/skills/ipal-reference/SKILL.md @@ -34,6 +34,7 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `twoFactor.plugin` | — (required) | injected `payloadTotp` (the plugin does not import the peer) | missing function → throws | | `twoFactor.collectionSlug` | the panel's login collection (`admin.user`, else the first auth collection) | collection with 2FA; startup fails with `[ipal] twoFactor…` when it is not an auth collection or differs from `admin.user` | point it at the login collection | | `twoFactor.provider` | `'@intecion/ipal-kit/admin#TotpRedirectProvider'` | admin provider that sends users to `setup-totp` / `verify-totp` (path read in the browser); replaces the package's header-based one | own component path / `{ path, clientProps, serverProps }` (gets clientProps `forceSetup`); `false` keeps the package's (needs `x-pathname` on `/admin`, else `setup-totp?back=null` loops) | +| `twoFactor.texts` | ipal-kit's en/pl texts (`TOTP_TEXTS`) over the package's; 2FA screens titled "Two-step verification" / "Weryfikacja dwuetapowa" (site's language) | `false` = the package's texts; one text: `i18n.translations..totpPlugin.` (security.md) | | `twoFactor.allowCollectionMismatch` | `false` | allows `collectionSlug` ≠ `admin.user` (panel users of the other collection then skip 2FA) | `true` only when you protect a second auth collection on purpose | | `whiteLabel` | none | `admin.components.graphics.Logo/Icon` (`AdminLogo`/`AdminIcon`) from Site settings + vendor credit | omit / `false`; `true` = defaults | | `whiteLabel.settingsSlug` | `'site-settings'` | global it reads the logo/name from | — | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index eb08043..c11dd1c 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -144,7 +144,9 @@ Fifteen ready blocks and ten page templates. **Use a library block (or a variant |---|---|---| | `ConsentProvider` | `@intecion/ipal-kit/client` | Consent provider: `{ texts, cookieMap?, logEndpoint? }` — consent state, cookie, Consent Mode, deleting cookies after consent is withdrawn, optional POST of the decision to the log (`'/api/ipal/consent'`). Wrap the layout once; required by the banner, `Analytics`, `ConsentScript`. | | `CookieBanner` | `@intecion/ipal-kit/client` | Consent banner + category settings: `settings: 'inline' \| 'modal' \| 'detailed'`, `controls`, `equalChoice` (recommended `true`), `order`, `settingsActions`, `icon`, `classNames`; colours from `--ipal-*` CSS vars. Do not write your own banner. | -| `CookieButton` | `@intecion/ipal-kit/client` | Floating button that reopens the cookie settings (withdrawing consent); hidden while the banner is visible. Prop `className`. | +| `CookieButton` | `@intecion/ipal-kit/client` | Floating button that reopens the cookie settings (withdrawing consent); hidden while the banner is visible. Props `className`, `side` (`'left' \| 'right'`), `avoid` (selector it lifts above, default `COOKIE_BUTTON_AVOID` = footer; `false`). Tokens `--ipal-cookie-button-offset`, `--ipal-cookie-button-inset`. Type `CookieButtonProps`. | +| `COOKIE_BUTTON_AVOID`, `bottomOverlap(tops, viewportHeight)` | `@intecion/ipal-kit/client` | Default footer selector; pixels the footer covers at the bottom of the screen (how far the button moves up) | +| `TOTP_TEXTS`, `TOTP_VIEW_TITLE` | `@intecion/ipal-kit` | en/pl texts of the 2FA screens (`totpPlugin:*`, merged by `twoFactor`) and their tab title | | `ConsentScript` | `@intecion/ipal-kit/client` | Loads an external script (`src` or `code`) only after consent for `category` — for vendors without Consent Mode (chat, Plausible etc.). Inside `ConsentProvider`. | | `CookieTable` | `@intecion/ipal-kit/rsc` | Server Component: cookie table for the cookie policy page — `{ rows, labels?, locale?, categories?, caption?, classNames?, storageColumn?, storageTypes? }`; `rows` from `getCookieTable()`; a **Type** column when a row is local / session storage (`storageColumn: 'auto' \| boolean`). | | `useConsent(options?)` | `@intecion/ipal-kit/client` | Low-level consent state hook → `{ state, decided, consentId, acceptAll, rejectAll, savePreferences, reopen }`. Usually use `ConsentProvider` + `useConsentContext` (the provider calls it itself). | diff --git a/docs/consent.md b/docs/consent.md index db573ea..25daa6e 100644 --- a/docs/consent.md +++ b/docs/consent.md @@ -105,7 +105,12 @@ takes `locale` and optional `labels`; defaults: `COOKIE_TABLE_LABELS` (`@intecio | `controls` | `'checkbox'` | `'checkbox' \| 'switch'` | | `settingsActions` | `['back', 'save']` | buttons under the categories (`'accept' \| 'back' \| 'reject' \| 'save'`) | -`CookieButton` takes only `className` (replaces the default). +`CookieButton` props: `className` (replaces the default classes; position is then yours too), +`side` (`'left'` default or `'right'`), `avoid` (CSS selector, default `COOKIE_BUTTON_AVOID` = +`'footer, [role="contentinfo"]'`; `false` = never move). While the footer is on screen the button +moves up by its visible part (`bottomOverlap`), so it never covers footer links. Position tokens: +`--ipal-cookie-button-offset` (from the bottom, default `1rem`), `--ipal-cookie-button-inset` (from the +side, default `1rem`); z-index `--ipal-z-header`. Type `CookieButtonProps`. ## Overriding the look (Level 2) diff --git a/docs/dev/admin-ux.md b/docs/dev/admin-ux.md index 57003d3..f5bd3f0 100644 --- a/docs/dev/admin-ux.md +++ b/docs/dev/admin-ux.md @@ -80,6 +80,7 @@ Use these terms everywhere: labels, descriptions, docs, toasts. Never a synonym. | The whole website | site | `witryna` | website, page, domain | | A blog/news entry | post | `wpis` | article (unless the project calls it so) | | Electronic mail | e-mail | `e-mail` | email, mail | +| Code from an authenticator app at login | two-step verification (2FA in short labels) | `weryfikacja dwuetapowa` | TOTP, two-factor authentication | | Cookie consent | consent | `zgoda` | permission, opt-in | | Cookie consent banner | cookie banner | `baner cookies` | popup, consent bar, CookieBanner | | Form entry sent by a visitor | submission | `zgłoszenie` | entry, response, lead | diff --git a/docs/i18n.md b/docs/i18n.md index fd2238a..4fb7a70 100644 --- a/docs/i18n.md +++ b/docs/i18n.md @@ -378,7 +378,10 @@ about the matcher — paste it inline. This is a Next limitation, not a plugin o ## Admin panel languages and texts The site's content languages (`i18n.locales`) and the **admin panel's** language are -separate. The panel's language is what each user picks in *Account → Language*. +separate. The panel's language is what each user picks in *Account → Language*; until they pick one, +Payload takes the browser's language (English or Polish), else `i18n.fallbackLanguage` (Payload's +default `en`). An English browser therefore gets an English panel — 2FA screens included — on a +Polish site; set `i18n.fallbackLanguage: 'pl'` in your config to change the last step. - **Default:** when the project's `buildConfig` has no `i18n.supportedLanguages`, ipal-kit sets English and Polish. A project that sets its own list keeps it, untouched: diff --git a/docs/security.md b/docs/security.md index 75e0121..8b4aa5b 100644 --- a/docs/security.md +++ b/docs/security.md @@ -402,6 +402,22 @@ pnpm generate:importmap `src/app/(payload)/admin/importMap.js` must list `@intecion/ipal-kit/admin#TotpRedirectProvider` and `@clocklimited/payload-2fa/rsc#TOTPSetup` / `#TOTPVerify` / `#TOTPField`. Commit the file. +### Texts of the 2FA screens (`twoFactor.texts`) + +The setup and verify screens and the user field read their texts through Payload's i18n +(`totpPlugin:*`), in the user's admin language (*Account → Language*; without a choice, the +browser's language — an English browser sees English screens on a Polish site). The package's own texts are long and informal, +so ipal-kit merges `TOTP_TEXTS` (English and Polish, per `docs/dev/admin-ux.md`) over them, e.g. +"Two-step verification" / "Weryfikacja dwuetapowa", "Enter the 6-digit code from the app:" / +"Wpisz 6-cyfrowy kod z aplikacji:". The browser tab reads "Weryfikacja dwuetapowa — | Panel" +(`TOTP_VIEW_TITLE` in the site's default language: Payload's view title is a plain string). + +- **Override one text:** `i18n.translations..totpPlugin.` in your config — your keys win + over both sets. +- **Keep the package's texts:** `twoFactor: { …, texts: false }`. +- **Not translatable:** a network failure while sending the code shows the package's hardcoded + "Something went wrong" toast (rare: the server's own errors are translated). + ### The redirect to the 2FA screens (`twoFactor.provider`) The package's own admin provider decides on the server where to send the user, from an `x-pathname` diff --git a/src/exports/client.ts b/src/exports/client.ts index e6f33e5..0b12af7 100644 --- a/src/exports/client.ts +++ b/src/exports/client.ts @@ -15,14 +15,16 @@ export { shouldLoadGoogle } from '../modules/analytics/shouldLoadGoogle.js' * client-only code. */ export { + bottomOverlap, ConsentProvider, ConsentScript, + COOKIE_BUTTON_AVOID, CookieBanner, CookieButton, useConsent, useConsentContext, } from '../modules/consent/client.js' -export type { CookieBannerAction, CookieBannerClassNames, CookieSettingsAction } from '../modules/consent/client.js' +export type { CookieBannerAction, CookieBannerClassNames, CookieButtonProps, CookieSettingsAction } from '../modules/consent/client.js' export { ConstructionNotice } from '../modules/construction/ConstructionNotice.js' export type { ConstructionNoticeClassNames } from '../modules/construction/ConstructionNotice.js' export { CONSTRUCTION_CLOSE_LABEL, CONSTRUCTION_CLOSE_LABEL_PL, constructionCloseLabel } from '../modules/construction/texts.js' diff --git a/src/index.ts b/src/index.ts index 6e12c2f..b2d0132 100644 --- a/src/index.ts +++ b/src/index.ts @@ -316,8 +316,9 @@ export type { TotpUser, WithSecurityConfigOptions, } from './modules/security/index.js' - export type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js' + +export { TOTP_TEXTS, TOTP_VIEW_TITLE } from './modules/security/totp/totpTexts.js' export type { OgImage } from './modules/seo/buildMetadata.js' export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js' export { diff --git a/src/modules/consent/CookieButton.tsx b/src/modules/consent/CookieButton.tsx index 8d173cb..6762b35 100644 --- a/src/modules/consent/CookieButton.tsx +++ b/src/modules/consent/CookieButton.tsx @@ -1,22 +1,42 @@ 'use client' +import type { CSSProperties } from 'react' + import { Cookie } from 'lucide-react' +import { useEffect, useRef, useState } from 'react' import { useConsentContext } from './ConsentContext.js' import { useIsMounted } from './useIsMounted.js' +/** Elements the button moves up for, so it never covers footer links. */ +export const COOKIE_BUTTON_AVOID = 'footer, [role="contentinfo"]' + +export type CookieButtonProps = { + /** + * CSS selector of elements the button lifts above while they are on screen + * (default: the site footer). `false` = never move. + */ + avoid?: false | string + /** Replaces the default classes (look and position). The lift above `avoid` still applies. */ + className?: string + /** Corner. Default 'left'. */ + side?: 'left' | 'right' +} + /** * Floating "cookie settings" button — lets visitors reopen the consent panel * after deciding (GDPR: withdrawing consent must be as easy as giving it). * Hidden while the banner is showing. * * Colours follow the same design tokens as CookieBanner (--ipal-surface, - * --ipal-border, --ipal-hover, --ipal-text), so a client's palette applies to - * both without touching either component. Pass className to - * replace the styling outright. + * --ipal-border, --ipal-hover, --ipal-text). Position: --ipal-cookie-button-offset + * (distance from the bottom, default 1rem), --ipal-cookie-button-inset (from the + * side, default 1rem), z-index --ipal-z-header. When the footer scrolls into + * view the button moves up by the visible part of it, so footer links stay free. */ -export function CookieButton({ className }: { className?: string } = {}) { +export function CookieButton({ avoid = COOKIE_BUTTON_AVOID, className, side = 'left' }: CookieButtonProps = {}) { const isMounted = useIsMounted() const { decided, reopen, texts } = useConsentContext() + const lift = useLiftAbove(avoid, isMounted && decided) // Render nothing until mounted — prevents hydration mismatch (no project // ConsentWrapper workaround needed). @@ -25,9 +45,18 @@ export function CookieButton({ className }: { className?: string } = {}) { const cls = className ?? - 'fixed bottom-4 left-4 z-40 flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-colors ' + + 'flex h-11 w-11 items-center justify-center rounded-full border shadow-md transition-[background-color,transform] ' + 'bg-[var(--ipal-surface,light-dark(#fff,var(--ipal-surface-dark,#171717)))] border-[var(--ipal-border,light-dark(#e5e5e5,var(--ipal-border-dark,#262626)))] hover:bg-[var(--ipal-hover,light-dark(#f5f5f5,var(--ipal-hover-dark,#262626)))]' + const position: CSSProperties = className + ? {} + : { + bottom: 'calc(var(--ipal-cookie-button-offset, 1rem) + env(safe-area-inset-bottom, 0px))', + position: 'fixed', + [side]: 'var(--ipal-cookie-button-inset, 1rem)', + zIndex: 'var(--ipal-z-header, 40)' as unknown as number, + } + return (