🚩(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:
@@ -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'),
|
||||
);
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user