From 96c06162e62cf55aac329a8a615bef4355b22ffb Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 7 May 2026 02:02:29 +0200 Subject: [PATCH] =?UTF-8?q?fix(cards-web):=20inject=20=5F=5FPUBLIC=5FMANA?= =?UTF-8?q?=5FAUTH=5FURL=5F=5F=20on=20SSR=20=E2=80=94=20login=20was=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createManaAuthStore from @mana/shared-auth-ui reads the auth backend URL from window.__PUBLIC_MANA_AUTH_URL__ at runtime. Without the injection it falls back to a relative URL, so signIn POSTs land at cards.mana.how/api/v1/auth/login (SvelteKit 404, HTML body) instead of auth.mana.how/api/v1/auth/login. Adds a hooks.server.ts modeled after the mana-web one, but trimmed to the two URLs the standalone app actually consumes today (auth + sync). The values come from PUBLIC_MANA_AUTH_URL_CLIENT and PUBLIC_MANA_SYNC_URL_CLIENT in docker-compose.macmini.yml. Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/cards/apps/web/src/hooks.server.ts | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 apps/cards/apps/web/src/hooks.server.ts diff --git a/apps/cards/apps/web/src/hooks.server.ts b/apps/cards/apps/web/src/hooks.server.ts new file mode 100644 index 000000000..c8b0d19df --- /dev/null +++ b/apps/cards/apps/web/src/hooks.server.ts @@ -0,0 +1,32 @@ +import type { Handle } from '@sveltejs/kit'; + +/** + * Inject the runtime client URLs into on every SSR'd page. + * + * `@mana/shared-auth-ui` reads `window.__PUBLIC_MANA_AUTH_URL__` to know + * where to POST /api/v1/auth/login (and friends). Without this hook the + * client falls back to a relative URL → 404 on cards.mana.how. + * + * `process.env.PUBLIC_MANA_*_URL_CLIENT` come from the container + * environment (docker-compose.macmini.yml). $env/static/public would + * bake the URLs at build time; we want runtime so the same image can + * serve dev and prod. + */ + +const PUBLIC_MANA_AUTH_URL_CLIENT = + process.env.PUBLIC_MANA_AUTH_URL_CLIENT || process.env.PUBLIC_MANA_AUTH_URL || ''; +const PUBLIC_MANA_SYNC_URL_CLIENT = + process.env.PUBLIC_MANA_SYNC_URL_CLIENT || process.env.PUBLIC_MANA_SYNC_URL || ''; + +export const handle: Handle = async ({ event, resolve }) => { + return resolve(event, { + transformPageChunk: ({ html }) => { + const envScript = + ``; + return html.replace('', `${envScript}`); + }, + }); +};