Herstel: uitnodigingslink bevat het admin-basispad

De frontend bouwde origin + inviteLink; op een host waar de root een aparte website is
leidde de link naar die website. Nu origin + BASE_URL + pad via buildAppUrl.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 12:44:25 +01:00
co-authored by Claude Sonnet 5.5
parent 61fa5ba65d
commit 0908f42213
6 changed files with 87 additions and 4 deletions
@@ -464,3 +464,9 @@
## Redeploy after the admin-files fix
**Timestamp**: 2026-11-08
**Run**: 610 (dispatch, deploy_asf_test only), head d0c1d26, all gates and deploy-asf-test green. Live checks: /admin/ , /admin/index.html, /admin/favicon-theme.png (image/png), hashed css (text/css, contains the ASF palette) and js (text/javascript) all 200; /admin/dashboard 200 SPA; /admin/assets/missing.js and /api/v1/unknown 404 with empty body; /assets/missing.js 404 with the website 404 page; /health version 1.0.0+d0c1d26.
## Defect on the live ASF test host: invitation link pointed at the website root
**Timestamp**: 2026-11-08
**Found by**: Bryan; analysed with CMS & API.
**Root cause**: the API returns an app-relative path (`/invite/complete?token=...`); the frontend built the shown/copied URL as `origin + inviteLink` in InviteUserDialog (2x) and UsersPage, ignoring the router basepath (`/admin/` in builds). On ASF the root is the prerendered website, so the link hit its 404 page; SlpSoftware only worked through its root SPA fallback.
**Fix** (frontend only; API contract and shared Identity unchanged, SlpSoftware unaffected, already-issued links keep working there): `lib/links.ts buildAppUrl = origin + BASE_URL (no trailing slash) + path`, used in the 3 places. Tests: helper (prod/dev base, trailing slashes, missing leading slash, no double slash, encoded token), dialog link value. Frontend 304 tests green.
@@ -53,7 +53,13 @@ describe('InviteUserDialog', () => {
await userEvent.click(screen.getByTestId('invite-dialog-submit'));
expect(await screen.findByTestId('invite-dialog-link-input')).toBeInTheDocument();
const linkInput = await screen.findByTestId('invite-dialog-link-input');
expect(linkInput).toBeInTheDocument();
// origin + app base + the path from the API (base is '/' under test, '/admin/' in a build).
expect((linkInput as HTMLInputElement).value).toBe(
`${window.location.origin}${import.meta.env.BASE_URL.replace(/\/+$/, '')}/invite/complete?token=${(linkInput as HTMLInputElement).value.split('token=')[1]}`,
);
expect((linkInput as HTMLInputElement).value).toContain('/invite/complete?token=');
expect(screen.getByTestId('invite-dialog-copy')).toBeInTheDocument();
});
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { buildAppUrl } from '@/lib/links';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { toast } from 'sonner';
@@ -79,7 +80,7 @@ export function InviteUserDialog({ open, onOpenChange }: InviteUserDialogProps)
const handleCopy = async () => {
if (!inviteLink) return;
await navigator.clipboard.writeText(`${window.location.origin}${inviteLink}`);
await navigator.clipboard.writeText(buildAppUrl(inviteLink));
toast.success(t('users.actions.linkCopied'));
};
@@ -163,7 +164,7 @@ export function InviteUserDialog({ open, onOpenChange }: InviteUserDialogProps)
<div className="space-y-2">
<Label>{t('users.invite.linkLabel')}</Label>
<Input
value={`${window.location.origin}${inviteLink ?? ''}`}
value={inviteLink ? buildAppUrl(inviteLink) : ''}
readOnly
data-testid="invite-dialog-link-input"
/>
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { buildAppUrl } from '@/lib/links';
import { toast } from 'sonner';
import { useTranslation } from 'react-i18next';
import { MoreHorizontal, Link as LinkIcon, Trash2, UserX, UserCheck } from 'lucide-react';
@@ -102,7 +103,7 @@ export function UsersPage() {
const handleCopyInviteLink = async (user: UserListItem) => {
if (!user.inviteLink) return;
await navigator.clipboard.writeText(`${window.location.origin}${user.inviteLink}`);
await navigator.clipboard.writeText(buildAppUrl(user.inviteLink));
toast.success(t('users.actions.linkCopied'));
};
+51
View File
@@ -0,0 +1,51 @@
import { describe, expect, it } from 'vitest';
import { buildAppUrl } from '@/lib/links';
const ORIGIN = 'https://test.andreaslop.nl';
describe('buildAppUrl', () => {
it('puts the admin base path between origin and path (production build)', () => {
expect(buildAppUrl('/invite/complete?token=abc', '/admin/', ORIGIN)).toBe(
'https://test.andreaslop.nl/admin/invite/complete?token=abc',
);
});
it('works without a trailing slash on the base', () => {
expect(buildAppUrl('/invite/complete?token=abc', '/admin', ORIGIN)).toBe(
'https://test.andreaslop.nl/admin/invite/complete?token=abc',
);
});
it('adds nothing for the root base (dev server)', () => {
expect(buildAppUrl('/invite/complete?token=abc', '/', 'http://localhost:5173')).toBe(
'http://localhost:5173/invite/complete?token=abc',
);
});
it('tolerates a path without a leading slash', () => {
expect(buildAppUrl('invite/complete', '/admin/', ORIGIN)).toBe('https://test.andreaslop.nl/admin/invite/complete');
});
it('keeps an encoded token intact', () => {
expect(buildAppUrl('/invite/complete?token=a%2Fb%3D', '/admin/', ORIGIN)).toBe(
'https://test.andreaslop.nl/admin/invite/complete?token=a%2Fb%3D',
);
});
it.each([
['/admin/', '/invite/complete?token=a'],
['/admin//', '/invite/complete?token=a'],
['/admin', 'invite/complete?token=a'],
['/', '/invite/complete?token=a'],
['', 'invite/complete?token=a'],
])('never produces a double or missing slash (base %j, path %j)', (base, path) => {
const url = buildAppUrl(path, base, ORIGIN);
expect(url.replace('https://', '')).not.toContain('//');
expect(url).toMatch(/^https:\/\/test\.andreaslop\.nl(\/admin)?\/invite\/complete\?token=a$/);
});
it('defaults to the Vite base and the current origin', () => {
expect(buildAppUrl('/x')).toBe(`${window.location.origin}${import.meta.env.BASE_URL.replace(/\/+$/, '')}/x`);
});
});
+18
View File
@@ -0,0 +1,18 @@
/**
* Turns an app-relative path from the API (for example an invitation link,
* `/invite/complete?token=...`) into an absolute URL a person can open.
*
* The admin is mounted under a base path ('/admin/' in builds, '/' in dev), which is the same value the
* router uses as its basepath. Prefixing only the origin would point at the host root, which on a host
* that serves a separate website there is that website's page, not this app.
*/
export function buildAppUrl(
appPath: string,
base: string = import.meta.env.BASE_URL,
origin: string = window.location.origin,
): string {
const trimmedBase = base.replace(/\/+$/, '');
const path = appPath.startsWith('/') ? appPath : `/${appPath}`;
return `${origin}${trimmedBase}${path}`;
}