🛂(frontend) redirect to correct url after login
If a user wanted to access a doc but was not logged in, they would be redirected to the login page. After logging in, they would be redirected to the home page. This change makes it so that they are redirected to the doc they originally wanted to access. Usefull from the mail sent to the user to access the doc they were invited to.
This commit is contained in:
2
.github/workflows/impress-frontend.yml
vendored
2
.github/workflows/impress-frontend.yml
vendored
@@ -99,7 +99,7 @@ jobs:
|
||||
test-e2e:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-front
|
||||
timeout-minutes: 15
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -147,7 +147,7 @@ export const mockedDocument = async (page: Page, json: object) => {
|
||||
if (request.method().includes('GET') && !request.url().includes('page=')) {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
id: 'b0df4343-c8bd-4c20-9ff6-fbf94fc94egg',
|
||||
id: 'mocked-document-id',
|
||||
content: '',
|
||||
title: 'Mocked document',
|
||||
accesses: [],
|
||||
|
||||
@@ -7,19 +7,6 @@ test.beforeEach(async ({ page }) => {
|
||||
});
|
||||
|
||||
test.describe('Doc Editor', () => {
|
||||
test('checks the Doc Editor interact correctly', async ({
|
||||
page,
|
||||
browserName,
|
||||
}) => {
|
||||
const randomDoc = await createDoc(page, 'doc-editor', browserName, 1);
|
||||
|
||||
await expect(page.locator('h2').getByText(randomDoc[0])).toBeVisible();
|
||||
|
||||
await page.locator('.ProseMirror.bn-editor').click();
|
||||
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
|
||||
await expect(page.getByText('Hello World')).toBeVisible();
|
||||
});
|
||||
|
||||
test('checks the Doc is connected to the webrtc server', async ({
|
||||
page,
|
||||
browserName,
|
||||
|
||||
@@ -122,22 +122,14 @@ test.describe('Doc Export', () => {
|
||||
// Add a list
|
||||
await page.locator('.bn-block-outer').last().click();
|
||||
await page.keyboard.press('Enter');
|
||||
await page.locator('.bn-block-outer').last().fill('Test List 1');
|
||||
await page.getByText('Test List 1').dblclick();
|
||||
await page.locator('.bn-block-outer').last().fill('/');
|
||||
await page.getByText('Bullet List').click();
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: 'Paragraph',
|
||||
})
|
||||
.click();
|
||||
await page
|
||||
.getByRole('menuitem', {
|
||||
name: 'Bullet List',
|
||||
})
|
||||
.click();
|
||||
await page
|
||||
.locator('.bn-block-content[data-content-type="bulletListItem"]')
|
||||
.locator('.bn-block-content[data-content-type="bulletListItem"] p')
|
||||
.last()
|
||||
.click();
|
||||
.fill('Test List 1');
|
||||
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||
await page.waitForTimeout(300);
|
||||
await page.keyboard.press('Enter');
|
||||
await page
|
||||
.locator('.bn-block-content[data-content-type="bulletListItem"] p')
|
||||
@@ -155,22 +147,14 @@ test.describe('Doc Export', () => {
|
||||
// Add a number list
|
||||
await page.locator('.bn-block-outer').last().click();
|
||||
await page.keyboard.press('Enter');
|
||||
await page.locator('.bn-block-outer').last().fill('Test Number 1');
|
||||
await page.getByText('Test Number 1').dblclick();
|
||||
await page.locator('.bn-block-outer').last().fill('/');
|
||||
await page.getByText('Numbered List').click();
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: 'Paragraph',
|
||||
})
|
||||
.click();
|
||||
await page
|
||||
.getByRole('menuitem', {
|
||||
name: 'Numbered List',
|
||||
})
|
||||
.click();
|
||||
await page
|
||||
.locator('.bn-block-content[data-content-type="numberedListItem"]')
|
||||
.locator('.bn-block-content[data-content-type="numberedListItem"] p')
|
||||
.last()
|
||||
.click();
|
||||
.fill('Test Number 1');
|
||||
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||
await page.waitForTimeout(300);
|
||||
await page.keyboard.press('Enter');
|
||||
await page
|
||||
.locator('.bn-block-content[data-content-type="numberedListItem"] p')
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
});
|
||||
import { keyCloakSignIn } from './common';
|
||||
|
||||
test.describe('Doc Routing', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test('checks alias docs url with homepage', async ({ page }) => {
|
||||
await expect(page).toHaveURL('/');
|
||||
|
||||
@@ -14,9 +16,9 @@ test.describe('Doc Routing', () => {
|
||||
|
||||
await expect(buttonCreateHomepage).toBeVisible();
|
||||
|
||||
await page.goto('/docs');
|
||||
await page.goto('/docs/');
|
||||
await expect(buttonCreateHomepage).toBeVisible();
|
||||
await expect(page).toHaveURL(/\/docs$/);
|
||||
await expect(page).toHaveURL(/\/docs\/$/);
|
||||
});
|
||||
|
||||
test('checks 404 on docs/[id] page', async ({ page }) => {
|
||||
@@ -33,3 +35,16 @@ test.describe('Doc Routing', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('Doc Routing: Not loggued', () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } });
|
||||
|
||||
test('checks redirect to a doc after login', async ({
|
||||
page,
|
||||
browserName,
|
||||
}) => {
|
||||
await page.goto('/docs/mocked-document-id/');
|
||||
await keyCloakSignIn(page, browserName);
|
||||
await expect(page).toHaveURL(/\/docs\/mocked-document-id\/$/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,11 +2,11 @@ import { expect, test } from '@playwright/test';
|
||||
|
||||
import { keyCloakSignIn } from './common';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test.describe('Header', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/');
|
||||
});
|
||||
|
||||
test('checks all the elements are visible', async ({ page }) => {
|
||||
const header = page.locator('header').first();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { PropsWithChildren, useEffect } from 'react';
|
||||
import { Box } from '@/components';
|
||||
|
||||
import { useAuthStore } from './useAuthStore';
|
||||
|
||||
export const Auth = ({ children }: PropsWithChildren) => {
|
||||
const { authenticated, initAuth } = useAuthStore();
|
||||
|
||||
|
||||
1
src/frontend/apps/impress/src/core/auth/conf.ts
Normal file
1
src/frontend/apps/impress/src/core/auth/conf.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const PATH_AUTH_LOCAL_STORAGE = 'docs-path-auth';
|
||||
@@ -3,6 +3,7 @@ import { create } from 'zustand';
|
||||
import { baseApiUrl } from '@/core/conf';
|
||||
|
||||
import { User, getMe } from './api';
|
||||
import { PATH_AUTH_LOCAL_STORAGE } from './conf';
|
||||
|
||||
interface AuthStore {
|
||||
authenticated: boolean;
|
||||
@@ -23,9 +24,26 @@ export const useAuthStore = create<AuthStore>((set) => ({
|
||||
initAuth: () => {
|
||||
getMe()
|
||||
.then((data: User) => {
|
||||
// If a path is stored in the local storage, we redirect to it
|
||||
const path_auth = localStorage.getItem(PATH_AUTH_LOCAL_STORAGE);
|
||||
if (path_auth) {
|
||||
localStorage.removeItem(PATH_AUTH_LOCAL_STORAGE);
|
||||
window.location.replace(path_auth);
|
||||
return;
|
||||
}
|
||||
|
||||
set({ authenticated: true, userData: data });
|
||||
})
|
||||
.catch(() => {
|
||||
// If we try to access a specific page and we are not authenticated
|
||||
// we store the path in the local storage to redirect to it after login
|
||||
if (window.location.pathname !== '/') {
|
||||
localStorage.setItem(
|
||||
PATH_AUTH_LOCAL_STORAGE,
|
||||
window.location.pathname,
|
||||
);
|
||||
}
|
||||
|
||||
window.location.replace(new URL('authenticate/', baseApiUrl()).href);
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user