From 1e89eb1a21c894918a039b241e779b2cd7691adf Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Fri, 27 Sep 2024 15:52:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=82(frontend)=20redirect=20to=20the=20?= =?UTF-8?q?OIDC=20when=20private=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now redirect to the OIDC when a user is on a private doc and is not authentified. --- CHANGELOG.md | 5 ++-- .../app-impress/doc-visibility.spec.ts | 27 +++++++++++++++++++ .../apps/impress/src/core/AppProvider.tsx | 1 + .../impress/src/pages/docs/[id]/index.tsx | 7 +++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec30b59b8..75d84e2ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,9 @@ and this project adheres to ## Fixed -- 🐛 (backend) gitlab oicd userinfo endpoint #232 -- ♻️ (backend) getting list of document versions available for a user #258 +- 🐛(backend) gitlab oicd userinfo endpoint #232 +- 🛂(frontend) redirect to the OIDC when private doc and unauthentified #292 +- ♻️(backend) getting list of document versions available for a user #258 ## [1.4.0] - 2024-09-17 diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts index 0e2366de9..08a4bdae1 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts @@ -93,4 +93,31 @@ test.describe('Doc Visibility: Not loggued', () => { await expect(page.locator('h2').getByText(docTitle)).toBeVisible(); }); + + test('A private doc redirect to the OIDC when not authentified.', async ({ + page, + browserName, + }) => { + test.slow(); + await page.goto('/'); + await keyCloakSignIn(page, browserName); + + const [docTitle] = await createDoc(page, 'My private doc', browserName, 1); + + await expect(page.locator('h2').getByText(docTitle)).toBeVisible(); + + const urlDoc = page.url(); + + await page + .getByRole('button', { + name: 'Logout', + }) + .click(); + + await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible(); + + await page.goto(urlDoc); + + await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible(); + }); }); diff --git a/src/frontend/apps/impress/src/core/AppProvider.tsx b/src/frontend/apps/impress/src/core/AppProvider.tsx index a578c9b84..596217c2f 100644 --- a/src/frontend/apps/impress/src/core/AppProvider.tsx +++ b/src/frontend/apps/impress/src/core/AppProvider.tsx @@ -17,6 +17,7 @@ const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 1000 * 60 * 3, + retry: 1, }, }, }); diff --git a/src/frontend/apps/impress/src/pages/docs/[id]/index.tsx b/src/frontend/apps/impress/src/pages/docs/[id]/index.tsx index 3acd004ce..2f2d92b97 100644 --- a/src/frontend/apps/impress/src/pages/docs/[id]/index.tsx +++ b/src/frontend/apps/impress/src/pages/docs/[id]/index.tsx @@ -5,6 +5,7 @@ import { useEffect, useState } from 'react'; import { Box, Text } from '@/components'; import { TextErrors } from '@/components/TextErrors'; +import { useAuthStore } from '@/core/auth'; import { DocEditor } from '@/features/docs'; import { useDoc } from '@/features/docs/doc-management'; import { MainLayout } from '@/layouts'; @@ -31,6 +32,7 @@ interface DocProps { } const DocPage = ({ id }: DocProps) => { + const { authenticated, login } = useAuthStore(); const { data: docQuery, isError, error } = useDoc({ id }); const [doc, setDoc] = useState(docQuery); @@ -58,6 +60,11 @@ const DocPage = ({ id }: DocProps) => { return null; } + if (error.status === 401 && !authenticated) { + login(); + return null; + } + return (