From bc127751b3b7ca5be65de95653d22d2ca5cb8d70 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 1 Feb 2024 10:51:31 +0800 Subject: [PATCH] fix(console): add default value for custom auth rules in protected app details (#5360) --- .../ProtectedAppSettings/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/ProtectedAppSettings/index.tsx b/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/ProtectedAppSettings/index.tsx index dfb90df1d..add22832d 100644 --- a/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/ProtectedAppSettings/index.tsx +++ b/packages/console/src/pages/ApplicationDetails/ApplicationDetailsContent/ProtectedAppSettings/index.tsx @@ -6,7 +6,7 @@ import { } from '@logto/schemas'; import { cond } from '@silverhand/essentials'; import classNames from 'classnames'; -import { type ChangeEvent, useState } from 'react'; +import { type ChangeEvent, useState, useEffect } from 'react'; import { Controller, useFieldArray, useFormContext } from 'react-hook-form'; import { Trans, useTranslation } from 'react-i18next'; import useSWR from 'swr'; @@ -56,6 +56,7 @@ function ProtectedAppSettings({ data }: Props) { control, register, getFieldState, + setValue, formState: { errors }, } = useFormContext(); @@ -64,6 +65,12 @@ function ProtectedAppSettings({ data }: Props) { name: 'protectedAppMetadata.pageRules', }); + useEffect(() => { + if (fields.length === 0) { + setValue('protectedAppMetadata.pageRules', [{ path: '' }]); + } + }, [fields.length, setValue]); + if (!data.protectedAppMetadata) { return null; }