From 9fc30d6bf633b906590b8662f71b831f211411a0 Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:15:48 +0200 Subject: [PATCH] fix(web): auth on navigation from shared link to timeline (#12385) --- e2e/src/web/specs/shared-link.e2e-spec.ts | 11 +++++++++++ web/src/lib/utils.ts | 2 +- web/src/routes/+layout.svelte | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/e2e/src/web/specs/shared-link.e2e-spec.ts b/e2e/src/web/specs/shared-link.e2e-spec.ts index fe7da0b2c0..8679bb3236 100644 --- a/e2e/src/web/specs/shared-link.e2e-spec.ts +++ b/e2e/src/web/specs/shared-link.e2e-spec.ts @@ -69,4 +69,15 @@ test.describe('Shared Links', () => { await page.goto('/share/invalid'); await page.getByRole('heading', { name: 'Invalid share key' }).waitFor(); }); + + test('auth on navigation from shared link to timeline', async ({ context, page }) => { + await utils.setAuthCookies(context, admin.accessToken); + + await page.goto(`/share/${sharedLink.key}`); + await page.getByRole('heading', { name: 'Test Album' }).waitFor(); + + await page.locator('a[href="/"]').click(); + await page.waitForURL('/photos'); + await page.locator(`[data-asset-id="${asset.id}"]`).waitFor(); + }); }); diff --git a/web/src/lib/utils.ts b/web/src/lib/utils.ts index 6c3add70ce..395d9796f4 100644 --- a/web/src/lib/utils.ts +++ b/web/src/lib/utils.ts @@ -156,7 +156,7 @@ export const getJobName = derived(t, ($t) => { let _key: string | undefined; let _sharedLink: SharedLinkResponseDto | undefined; -export const setKey = (key: string) => (_key = key); +export const setKey = (key?: string) => (_key = key); export const getKey = (): string | undefined => _key; export const setSharedLink = (sharedLink: SharedLinkResponseDto) => (_sharedLink = sharedLink); export const getSharedLink = (): SharedLinkResponseDto | undefined => _sharedLink; diff --git a/web/src/routes/+layout.svelte b/web/src/routes/+layout.svelte index b7335dea59..8f7f372efd 100644 --- a/web/src/routes/+layout.svelte +++ b/web/src/routes/+layout.svelte @@ -71,6 +71,8 @@ } beforeNavigate(({ from, to }) => { + setKey(isSharedLinkRoute(to?.route.id) ? to?.params?.key : undefined); + if (isAssetViewerRoute(from) && isAssetViewerRoute(to)) { return; }