🚩(project) add FRONTEND_SILENT_LOGIN_ENABLED feature flag

Not every project requires silent login.
This commit adds a new feature flag
FRONTEND_SILENT_LOGIN_ENABLED to enable or
disable silent login functionality.
This commit is contained in:
Anthony LC
2026-01-23 10:44:25 +01:00
parent c6ded3f267
commit 989c70ed57
9 changed files with 27 additions and 3 deletions

View File

@@ -1,9 +1,15 @@
import { expect, test } from '@playwright/test';
import { overrideConfig } from './utils-common';
test.describe('Login: Not logged', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('It tries silent login', async ({ page }) => {
await overrideConfig(page, {
FRONTEND_SILENT_LOGIN_ENABLED: true,
});
const silentLoginRequest = page.waitForRequest((request) =>
request.url().includes('/api/v1.0/authenticate/?silent=true'),
);

View File

@@ -14,6 +14,7 @@ export const CONFIG = {
FRONTEND_CSS_URL: null,
FRONTEND_JS_URL: null,
FRONTEND_HOMEPAGE_FEATURE_ENABLED: true,
FRONTEND_SILENT_LOGIN_ENABLED: false,
FRONTEND_THEME: null,
MEDIA_BASE_URL: 'http://localhost:8083',
LANGUAGES: [

View File

@@ -25,6 +25,7 @@ export interface ConfigResponse {
FRONTEND_CSS_URL?: string;
FRONTEND_HOMEPAGE_FEATURE_ENABLED?: boolean;
FRONTEND_JS_URL?: string;
FRONTEND_SILENT_LOGIN_ENABLED?: boolean;
FRONTEND_THEME?: Theme;
LANGUAGES: [string, string][];
LANGUAGE_CODE: string;

View File

@@ -26,8 +26,18 @@ export const Auth = ({ children }: PropsWithChildren) => {
const [isRedirecting, setIsRedirecting] = useState(false);
const { data: config } = useConfig();
const shouldTrySilentLogin = useMemo(
() => !authenticated && !hasTrySilent() && !isLoading && !isRedirecting,
[authenticated, isLoading, isRedirecting],
() =>
!authenticated &&
!hasTrySilent() &&
!isLoading &&
!isRedirecting &&
config?.FRONTEND_SILENT_LOGIN_ENABLED,
[
authenticated,
isLoading,
isRedirecting,
config?.FRONTEND_SILENT_LOGIN_ENABLED,
],
);
const shouldTryLogin =
!authenticated && !isLoading && !isRedirecting && !pathAllowed;