From 1518f1bbbe5499a5ed3a61e6fd0bc7270f926513 Mon Sep 17 00:00:00 2001 From: agent Date: Tue, 6 Oct 2026 10:35:15 +0000 Subject: [PATCH 01/21] Fix admin login/logout over HTTP and stale sessions - Auth cookie was always exported with the SDK default `Secure` flag, so browsers dropped it over plain HTTP (CADDY_SCHEME=http) and login looped back to /login. Set `secure` from the real request scheme. - Logout never ran: the hook redirected every authenticated request to /login (including POST /login?/logout) back to /pages. Only redirect GET. - Refresh the token per request so revoked tokens log the user out instead of surfacing as 500s, and sessions slide instead of expiring mid-edit. - Use `_superusers` instead of the deprecated `pb.admins` alias; keep the entered email on a failed login. - docker-compose: fully-qualified image names (podman rejects short names). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv --- app-admin/src/hooks.server.ts | 22 ++++++++++++++++++++-- app-admin/src/routes/login/+page.server.ts | 9 +++++---- docker-compose.yml | 4 ++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app-admin/src/hooks.server.ts b/app-admin/src/hooks.server.ts index ed21553..fcc88a5 100644 --- a/app-admin/src/hooks.server.ts +++ b/app-admin/src/hooks.server.ts @@ -7,6 +7,18 @@ export const handle: Handle = async ({ event, resolve }) => { event.request.headers.get('cookie') ?? '', env.POCKETBASE_INTERNAL_URL ); + + // `isValid` only checks the token's expiry locally. Refresh it against + // PocketBase so a revoked token (deleted user, changed password) logs the + // user out instead of failing later as a 500, and so active sessions slide. + if (event.locals.pb.authStore.isValid) { + const collection = event.locals.pb.authStore.record?.collectionName || '_superusers'; + try { + await event.locals.pb.collection(collection).authRefresh(); + } catch { + event.locals.pb.authStore.clear(); + } + } event.locals.user = event.locals.pb.authStore.record; const path = event.url.pathname; @@ -17,11 +29,17 @@ export const handle: Handle = async ({ event, resolve }) => { throw redirect(303, '/login'); } - if (isLoginRoute && isAuthed) { + if (isLoginRoute && isAuthed && event.request.method === 'GET') { throw redirect(303, '/pages'); } const response = await resolve(event); - response.headers.append('set-cookie', event.locals.pb.authStore.exportToCookie({ sameSite: 'lax' }, 'pb_auth')); + // The SDK defaults to `Secure`, which browsers drop over plain HTTP — that + // would make login impossible with CADDY_SCHEME=http. Match the real scheme + // (event.url comes from ORIGIN behind the proxy). + response.headers.append( + 'set-cookie', + event.locals.pb.authStore.exportToCookie({ sameSite: 'lax', secure: event.url.protocol === 'https:' }, 'pb_auth') + ); return response; }; diff --git a/app-admin/src/routes/login/+page.server.ts b/app-admin/src/routes/login/+page.server.ts index c68eec5..3062b49 100644 --- a/app-admin/src/routes/login/+page.server.ts +++ b/app-admin/src/routes/login/+page.server.ts @@ -9,13 +9,14 @@ export const actions: Actions = { try { try { - await locals.pb.admins.authWithPassword(email, password); + await locals.pb.collection('_superusers').authWithPassword(email, password); } catch { await locals.pb.collection('users').authWithPassword(email, password); } - } catch (err) { - console.error('Login failed for', email, err); - return fail(400, { message: 'Invalid email or password.' }); + } catch { + // One line per failed attempt; the full SDK error object is noise here. + console.warn('Admin login failed for', email); + return fail(400, { email, message: 'Invalid email or password.' }); } throw redirect(303, '/pages'); diff --git a/docker-compose.yml b/docker-compose.yml index 416bbc3..1b96633 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: pocketbase: - image: spectado/pocketbase:latest + image: docker.io/spectado/pocketbase:latest container_name: massage-pocketbase restart: unless-stopped # Internal only — accessed via the caddy reverse proxy @@ -73,7 +73,7 @@ services: - "3000" caddy: - image: caddy:2-alpine + image: docker.io/library/caddy:2-alpine container_name: massage-caddy restart: unless-stopped ports: From 52d7a5e3e24a9a118378cc16e3ab7d093e4b85c8 Mon Sep 17 00:00:00 2001 From: agent Date: Tue, 6 Oct 2026 10:35:15 +0000 Subject: [PATCH 02/21] Admin shell: standalone login/preview, fixed admin theme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /login and /preview no longer render the admin navbar (the login page showed Pages/Export/Logout to signed-out users; the page preview iframe showed the whole admin shell above the draft). - Site colours from Globals were written onto --color-primary/--color-accent of the admin document, which are DaisyUI's theme variables — so the brand colour restyled every admin button (low-contrast white-on-sage) and flashed after hydration. Apply them only inside /preview; give the admin its own sage primary at ~5:1 contrast. - Login page redesigned with DaisyUI 5 markup (full-width inputs, labels above), autocomplete hints, pending state. - Navbar: active-route highlight, consistent button sizes, wraps instead of overflowing on narrow screens. - Import: confirm before overwriting, show per-item errors instead of auto-reloading them away, friendly message for invalid JSON. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv --- app-admin/src/app.css | 11 ++ app-admin/src/routes/+layout.svelte | 148 +++++++++++++--------- app-admin/src/routes/login/+page.svelte | 64 ++++++---- app-admin/src/routes/preview/+page.svelte | 71 +++++++---- 4 files changed, 181 insertions(+), 113 deletions(-) diff --git a/app-admin/src/app.css b/app-admin/src/app.css index 84c1665..74c593c 100644 --- a/app-admin/src/app.css +++ b/app-admin/src/app.css @@ -4,6 +4,17 @@ themes: light --default; } +/* Admin UI theme: DaisyUI light with a fixed sage primary. Deliberately NOT + tied to the site's Globals → Colors (those only apply inside /preview), so + a light brand colour can't make admin buttons unreadable. #647556 on white + text is ~5:1 contrast (WCAG AA). */ +@plugin 'daisyui/theme' { + name: 'light'; + default: true; + --color-primary: #647556; + --color-primary-content: #ffffff; +} + @theme { --font-sans: 'DM Sans', ui-sans-serif, system-ui, sans-serif; --font-serif: 'Playfair Display', Georgia, serif; diff --git a/app-admin/src/routes/+layout.svelte b/app-admin/src/routes/+layout.svelte index 93aa833..877bbf8 100644 --- a/app-admin/src/routes/+layout.svelte +++ b/app-admin/src/routes/+layout.svelte @@ -1,13 +1,29 @@ @@ -80,48 +97,55 @@ -
- - {/each} - - {:else if block.type === 'hero'} - - - - - {:else if block.type === 'button'} -
- - -
- updateData({ variant: v })} - /> -
-
- updateData({ alignment: v })} - formatLabel={titleCase} - /> -
-
- updateData({ size: v })} - formatLabel={(v) => String({ xs: 'Extra Small', sm: 'Small', md: 'Medium', lg: 'Large' }[String(v)] || v)} - /> -
-
-
- Color -
- updateData({ color: e.currentTarget.value })} /> - updateData({ color: e.currentTarget.value })} /> -
-
-
-
- {:else if block.type === 'spacer'} -
- -
- {:else if block.type === 'testimonials'} -
- - - {#each block.data.items || [] as item, i} -
- - updateArray('items', i, { title: e.currentTarget.value })} - /> - -
- {/each} - -
- {:else if block.type === 'upcoming_calendar'} -
- - -
-
-

Category filters

-

Choose categories to show in this block. Leave all unchecked to show every published event.

-
- {#if eventCategories?.length} -
- {#each eventCategories as category} - - {/each} -
- {:else} -

No event categories exist yet. Create events in the Calendar admin page first.

- {/if} -
-
- {:else if block.type === 'shop'} - - {:else if block.type === 'checkout'} - - {/if} - -
- - -
- updateData({ _background: { ...(block.data._background || {}), type: v } })} - /> -
- - {#if block.data._background?.type === 'color'} -
- -
- {/if} - - {#if block.data._background?.type === 'image'} -
- updateData({ _background: { ...(block.data._background || {}), imageUrl: image.url, imageAlt: image.alt } })} /> - - updateData({ _background: { ...(block.data._background || {}), attachment: v } })} - /> - - updateData({ _background: { ...(block.data._background || {}), overlay: true, overlayOpacity: v } })} - formatLabel={(v) => `${v}%`} - /> -
- {/if} - -
- - updateData({ _foreground: { ...(block.data._foreground || {}), mode: v } })} - /> - - {#if block.data._foreground?.mode === 'custom'} -
-
-
- Heading -
- updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), headingColor: e.currentTarget.value } })} /> -
-
-
-
-
- Sub heading -
- updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), subheadingColor: e.currentTarget.value } })} /> -
-
-
-
-
- Text -
- updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} /> - updateData({ _foreground: { ...(block.data._foreground || {}), textColor: e.currentTarget.value } })} /> -
-
-
-
- {/if} -
-
-{/if} + + +{#snippet field(label: string, value: string, onInput: (value: string) => void, placeholder = '')} + +{/snippet} + +{#if !block} +
Select a block to edit.
+{:else} +
+

{blockLabels[block.type as BlockType]}

+ + {#if block.type === 'text'} + updateData({ content })} /> + {:else if block.type === 'image_text'} +
+ updateData(image)} /> + updateData({ imagePosition: v })} /> + updateData({ content })} /> +
+ {:else if block.type === 'timeline'} +
+ {#each block.data.items || [] as item, i} +
+
+ Item {i + 1} + +
+ updateArray('items', i, { title: e.currentTarget.value })} /> + +
+ {/each} + +
+ {:else if block.type === 'hero'} + {@render field('Heading', block.data.heading || '', (heading) => updateData({ heading }))} + {@render field('Subheading', block.data.subheading || '', (subheading) => updateData({ subheading }))} +
+ {@render field('Button label', block.data.buttonLabel || '', (buttonLabel) => updateData({ buttonLabel }))} + {@render field('Button URL', block.data.buttonUrl || '', (buttonUrl) => updateData({ buttonUrl }), '/page or https://…')} +
+ {:else if block.type === 'button'} +
+ {@render field('Button label', block.data.label || '', (label) => updateData({ label }))} + {@render field('URL', block.data.href || '', (href) => updateData({ href }), '/page or https://…')} +
+
+ updateData({ variant: v })} /> + updateData({ alignment: v })} /> + updateData({ size: v })} formatLabel={(v) => sizeLabels[String(v)] || String(v)} /> + updateData({ color })} /> +
+ {:else if block.type === 'spacer'} + + {:else if block.type === 'testimonials'} + {@render field('Section title', block.data.title || '', (title) => updateData({ title }))} +
+ {#each block.data.items || [] as item, i} +
+
+ Testimonial {i + 1} + +
+ + updateArray('items', i, { title: e.currentTarget.value })} /> +
+ {/each} + +
+ {:else if block.type === 'upcoming_calendar'} + {@render field('Section title', block.data.title || '', (title) => updateData({ title }))} +
+

Category filters

+

Choose categories to show in this block. Leave all unselected to show every published event.

+ {#if eventCategories?.length} +
+ {#each eventCategories as category} + + {/each} +
+ {:else} +

No event categories exist yet. Add categories to events in Calendar first.

+ {/if} +
+ {:else if block.type === 'shop'} + + {:else if block.type === 'checkout'} + + {/if} + +
+ updateBackground({ type })} /> + + {#if block.data._background?.type === 'color'} + updateBackground({ color })} /> + {:else if block.data._background?.type === 'image'} + updateBackground({ imageUrl: image.url, imageAlt: image.alt })} /> + updateBackground({ attachment })} /> + updateBackground({ overlay: Number(v) > 0, overlayOpacity: Number(v) })} + formatLabel={(v) => (Number(v) === 0 ? 'None' : `${v}%`)} + /> + {/if} + +
+ + updateForeground({ mode })} /> + + {#if block.data._foreground?.mode === 'custom'} + updateForeground({ headingColor })} /> + updateForeground({ subheadingColor })} /> + updateForeground({ textColor })} /> + {/if} +
+
+{/if} diff --git a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte index 5ecd756..a5874d1 100644 --- a/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/CheckoutBlockEditor.svelte @@ -15,17 +15,17 @@
-
diff --git a/app-admin/src/lib/admin/editors/ColorField.svelte b/app-admin/src/lib/admin/editors/ColorField.svelte new file mode 100644 index 0000000..c25f331 --- /dev/null +++ b/app-admin/src/lib/admin/editors/ColorField.svelte @@ -0,0 +1,37 @@ + + +
+ {label} +
+ onChange(e.currentTarget.value)} + /> + onChange(e.currentTarget.value.trim())} /> + {#if value} + + {/if} +
+
diff --git a/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte b/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte index 1b5a424..f01520e 100644 --- a/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte +++ b/app-admin/src/lib/admin/editors/EmailBlockEditor.svelte @@ -4,6 +4,7 @@ import RichTextEditor from './RichTextEditor.svelte'; import ImageUploader from './ImageUploader.svelte'; import SegmentedControl from './SegmentedControl.svelte'; + import ColorField from './ColorField.svelte'; let { block, primaryColor = '#8a9a7b', onChange = (block: EmailBlock) => {} } = $props<{ block: EmailBlock | null; @@ -17,11 +18,6 @@ onChange(block); } - function titleCase(value: string | number) { - const text = String(value); - return text.charAt(0).toUpperCase() + text.slice(1); - } - const autoFilled: Record = { booking_details: 'Filled in automatically with the booked services, date and time, prices and the total paid.', customer_details: "Filled in automatically with the customer's name, email, phone and checkout notes.", @@ -42,46 +38,38 @@
updateData(image)} /> updateData({ width: v })} formatLabel={(v) => `${v}%`} /> - updateData({ alignment: v })} formatLabel={titleCase} /> -
{:else if block.type === 'button'}
-
{:else if block.type === 'spacer'} -