Skip to content

Commit 1e89eb1

Browse files
committed
🛂(frontend) redirect to the OIDC when private doc
We now redirect to the OIDC when a user is on a private doc and is not authentified.
1 parent 413e0be commit 1e89eb1

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ and this project adheres to
1616

1717
## Fixed
1818

19-
- 🐛 (backend) gitlab oicd userinfo endpoint #232
20-
- ♻️ (backend) getting list of document versions available for a user #258
19+
- 🐛(backend) gitlab oicd userinfo endpoint #232
20+
- 🛂(frontend) redirect to the OIDC when private doc and unauthentified #292
21+
- ♻️(backend) getting list of document versions available for a user #258
2122

2223
## [1.4.0] - 2024-09-17
2324

src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,31 @@ test.describe('Doc Visibility: Not loggued', () => {
9393

9494
await expect(page.locator('h2').getByText(docTitle)).toBeVisible();
9595
});
96+
97+
test('A private doc redirect to the OIDC when not authentified.', async ({
98+
page,
99+
browserName,
100+
}) => {
101+
test.slow();
102+
await page.goto('/');
103+
await keyCloakSignIn(page, browserName);
104+
105+
const [docTitle] = await createDoc(page, 'My private doc', browserName, 1);
106+
107+
await expect(page.locator('h2').getByText(docTitle)).toBeVisible();
108+
109+
const urlDoc = page.url();
110+
111+
await page
112+
.getByRole('button', {
113+
name: 'Logout',
114+
})
115+
.click();
116+
117+
await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible();
118+
119+
await page.goto(urlDoc);
120+
121+
await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible();
122+
});
96123
});

src/frontend/apps/impress/src/core/AppProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const queryClient = new QueryClient({
1717
defaultOptions: {
1818
queries: {
1919
staleTime: 1000 * 60 * 3,
20+
retry: 1,
2021
},
2122
},
2223
});

src/frontend/apps/impress/src/pages/docs/[id]/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useState } from 'react';
55

66
import { Box, Text } from '@/components';
77
import { TextErrors } from '@/components/TextErrors';
8+
import { useAuthStore } from '@/core/auth';
89
import { DocEditor } from '@/features/docs';
910
import { useDoc } from '@/features/docs/doc-management';
1011
import { MainLayout } from '@/layouts';
@@ -31,6 +32,7 @@ interface DocProps {
3132
}
3233

3334
const DocPage = ({ id }: DocProps) => {
35+
const { authenticated, login } = useAuthStore();
3436
const { data: docQuery, isError, error } = useDoc({ id });
3537
const [doc, setDoc] = useState(docQuery);
3638

@@ -58,6 +60,11 @@ const DocPage = ({ id }: DocProps) => {
5860
return null;
5961
}
6062

63+
if (error.status === 401 && !authenticated) {
64+
login();
65+
return null;
66+
}
67+
6168
return (
6269
<Box $margin="large">
6370
<TextErrors

0 commit comments

Comments
 (0)