Fixed 2fa and white-label

This commit is contained in:
2026-10-12 13:10:34 +02:00
parent 13d669b757
commit 78e2f8fc7f
14 changed files with 322 additions and 161 deletions
+60 -39
View File
@@ -20,32 +20,32 @@ import { getPayload } from 'payload'
*/
type BrandingProps = {
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
/** Field holding the site name. Default 'siteName'. */
nameField?: string
/** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */
imageField?: string
/** Field holding the site name. Default 'siteName'. */
nameField?: string
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
}
type MediaLike = { url?: string | null } | null | undefined
type MediaLike = { url?: null | string } | null | undefined
async function loadBranding(
settingsSlug: string,
nameField: string,
imageField: string,
): Promise<{ name: string | null; url: string | null }> {
): Promise<{ name: null | string; url: null | string }> {
try {
// Consumer alias — resolved in the project's build, hidden from plugin tsc.
// @ts-ignore
const mod = (await import('@payload-config')) as { default: unknown }
const spec = '@payload-config'
const mod = (await import(spec)) as { default: unknown }
const payload = await getPayload({ config: mod.default as never })
const settings = (await payload.findGlobal({
slug: settingsSlug as never,
depth: 1,
})) as Record<string, unknown>
const name = typeof settings[nameField] === 'string' ? (settings[nameField] as string) : null
const name = typeof settings[nameField] === 'string' ? (settings[nameField]) : null
const image = settings[imageField] as MediaLike
const url =
image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null
@@ -55,65 +55,86 @@ async function loadBranding(
}
}
/** Admin panel logo (login screen + nav). SiteSettings `logo`, falls back to `siteName`. */
/**
* Admin panel logo — this is the LARGE logo on the login / unauthorized screens
* (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,
* falls back to `siteName` text. Sized generously for the login screen.
*/
export async function AdminLogo(props: BrandingProps = {}) {
const { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'logo' } = props
const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
if (url) {
return (
<img
src={url}
alt={name ?? ''}
style={{ maxHeight: 60, maxWidth: 240, width: 'auto', height: 'auto' }}
src={url}
style={{ height: 'auto', maxHeight: 120, maxWidth: 420, width: 'auto' }}
/>
)
}
if (name) return <div style={{ fontSize: '1.5rem', fontWeight: 600 }}>{name}</div>
if (name) {return <div style={{ fontSize: '2rem', fontWeight: 600 }}>{name}</div>}
return null // nothing configured → Payload's default
}
/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */
export async function AdminIcon(props: BrandingProps = {}) {
const { settingsSlug = 'site-settings', nameField = 'siteName', imageField = 'favicon' } = props
const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props
const { name, url } = await loadBranding(settingsSlug, nameField, imageField)
if (url) {
return (
<img
src={url}
alt={name ?? ''}
style={{ maxHeight: 28, maxWidth: 28, width: 'auto', height: 'auto' }}
src={url}
style={{ height: 'auto', maxHeight: 28, maxWidth: 28, width: 'auto' }}
/>
)
}
if (name) return <div style={{ fontWeight: 700 }}>{name.slice(0, 2).toUpperCase()}</div>
if (name) {return <div style={{ fontWeight: 700 }}>{name.slice(0, 2).toUpperCase()}</div>}
return null
}
/**
* Discreet vendor credit shown at the bottom of the admin nav: "Technology by
* Intecion.com". This is the PLUGIN VENDOR's credit (Intecion ships ipal-kit),
* not client data — so a sensible default here is fine and A0-safe. The client's
* own brand still owns the logo/name above (AdminLogo); this is a small line
* stating who provides the technology. Text/URL overridable; turn it off with
* `whiteLabel: { credit: false }`.
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
* data — a sensible default here is fine and A0-safe. The client's own brand
* still owns the logo/name; this is a small line stating who supports the tech.
* Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.
*
* Wired by ipalKit into admin.components.afterNavLinks.
* Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin
* (login screen footer). `variant` adjusts placement:
* - 'nav' → left-aligned line under the nav links
* - 'login' → centered line below the login form
*/
export function IntecionCredit(props: { text?: string; url?: string } = {}) {
const { text = 'Technology by Intecion.com', url = 'https://intecion.com' } = props
export function IntecionCredit(
props: { text?: string; url?: string; variant?: 'login' | 'nav' } = {},
) {
const {
text = 'Technology supported by Intecion.com',
url = 'https://intecion.com',
variant = 'nav',
} = props
const style =
variant === 'login'
? {
color: 'inherit' as const,
display: 'block',
fontSize: '0.75rem',
marginTop: '2rem',
opacity: 0.6,
padding: '0.5rem',
textAlign: 'center' as const,
textDecoration: 'none',
}
: {
color: 'inherit' as const,
display: 'block',
fontSize: '0.75rem',
opacity: 0.6,
padding: '0.75rem 1rem',
textDecoration: 'none',
}
return (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
style={{
display: 'block',
padding: '0.75rem 1rem',
fontSize: '0.75rem',
opacity: 0.6,
textDecoration: 'none',
}}
>
<a href={url} rel="noopener noreferrer" style={style} target="_blank">
{text}
</a>
)