Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to

## [Unreleased]

### Fixed

- 🐛(frontend) redirect home page to login when homepage feature is disabled #2521

## [v5.4.1] - 2026-07-09

### Changed
Expand Down
30 changes: 30 additions & 0 deletions src/frontend/apps/e2e/__tests__/app-impress/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,34 @@ test.describe('Home page', () => {
page.locator(`${process.env.SIGN_IN_EL_LOGIN_PAGE}`).getByText('impress'),
).toBeVisible();
});

test('it redirects a direct /home link to login when the homepage feature is disabled', async ({
page,
}) => {
await overrideConfig(page, {
FRONTEND_HOMEPAGE_FEATURE_ENABLED: false,
});

await page.goto('/home/');

// Keyclock login page
await expect(
page.locator(`${process.env.SIGN_IN_EL_LOGIN_PAGE}`).getByText('impress'),
).toBeVisible();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

test('it shows the homepage for a direct /home link when the homepage feature is enabled', async ({
page,
}) => {
await overrideConfig(page, {
FRONTEND_HOMEPAGE_FEATURE_ENABLED: true,
});

await page.goto('/home/');

// Homepage content, not the login page
await expect(
page.locator('h2').getByText('Govs ❤️ Open Source.'),
).toBeVisible();
});
});
22 changes: 20 additions & 2 deletions src/frontend/apps/impress/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { Loading } from '@/components';
import { useAuth } from '@/features/auth';
import { useConfig } from '@/core';
import { gotoLogin, useAuth } from '@/features/auth';
import { HomeContent } from '@/features/home';
import { NextPageWithLayout } from '@/types/next';

const Page: NextPageWithLayout = () => {
const { t } = useTranslation();
const { authenticated } = useAuth();
const { data: config, isFetched: isConfigFetched } = useConfig();
const { replace } = useRouter();
const homepageDisabled =
isConfigFetched && !config?.FRONTEND_HOMEPAGE_FEATURE_ENABLED;

/**
* If the user is authenticated we redirect him to the index page (grid).
Expand All @@ -24,7 +28,21 @@ const Page: NextPageWithLayout = () => {
void replace('/');
}, [authenticated, replace]);

if (authenticated) {
/**
* If the homepage feature is disabled, the homepage should not be reachable
* even from a direct link, so we redirect the user to the login page — the
* same behavior as visiting `/` (see the `Auth` component). We wait for the
* config to be fetched so a pending flag is not mistaken for a disabled one.
*/
useEffect(() => {
if (authenticated || !homepageDisabled) {
return;
}

gotoLogin(false);
}, [authenticated, homepageDisabled]);

if (authenticated || !isConfigFetched || homepageDisabled) {
return <Loading $height="100vh" $width="100vw" />;
}

Expand Down