Skip to content

Commit b8161eb

Browse files
committed
feat: auth page
1 parent 8e78c51 commit b8161eb

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

frontend/src/components/AuthPage/SignIn/BasicSignIn/BasicSignIn.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import AlertIcon from 'components/common/Icons/AlertIcon';
77
import { useNavigate } from 'react-router-dom';
88

99
import * as S from './BasicSignIn.styled';
10+
import { useQueryClient } from '@tanstack/react-query';
1011

1112
interface FormValues {
1213
username: string;
@@ -19,15 +20,16 @@ function BasicSignIn() {
1920
});
2021
const navigate = useNavigate();
2122
const { mutateAsync } = useAuthenticate();
23+
const client = useQueryClient();
2224

2325
const onSubmit = async (data: FormValues) => {
2426
await mutateAsync(data, {
25-
onSuccess(response) {
27+
onSuccess: async (response) => {
2628
if (response.raw.url.includes('error')) {
2729
methods.setError('root', { message: 'error' });
2830
} else {
31+
await client.invalidateQueries({queryKey: ['app', 'info']});
2932
navigate('/');
30-
window.location.reload();
3133
}
3234
},
3335
});

frontend/src/components/contexts/GlobalSettingsContext.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ export const GlobalSettingsProvider: React.FC<
2222
});
2323

2424
React.useEffect(() => {
25-
if (info.data?.raw.url.includes('auth')) {
25+
if (info.data?.redirect && !info.isFetching) {
2626
navigate('auth');
2727
return;
2828
}
2929

30-
info.data?.value().then((res) => {
31-
const features = res?.enabledFeatures || [];
30+
const features = info?.data?.response.enabledFeatures
31+
32+
if (features) {
3233
setValue({
3334
hasDynamicConfig: features.includes(
3435
ApplicationInfoEnabledFeaturesEnum.DYNAMIC_CONFIG
3536
),
36-
});
37-
});
37+
})
38+
}
3839
}, [info.data]);
3940

4041
return (

frontend/src/lib/hooks/api/appConfig.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
66
import {
77
ApplicationConfig,
88
ApplicationConfigPropertiesKafkaClusters,
9+
ApplicationInfo,
910
} from 'generated-sources';
1011
import { QUERY_REFETCH_OFF_OPTIONS } from 'lib/constants';
1112

@@ -29,8 +30,21 @@ export function useAuthenticate() {
2930
export function useAppInfo() {
3031
return useQuery(
3132
['app', 'info'],
32-
() => appConfig.getApplicationInfoRaw(),
33-
QUERY_REFETCH_OFF_OPTIONS
33+
async () => {
34+
const data = await appConfig.getApplicationInfoRaw()
35+
36+
let response: ApplicationInfo = {}
37+
try {
38+
response = await data.value()
39+
} catch {
40+
response = {}
41+
}
42+
43+
return {
44+
redirect: data.raw.url.includes('auth'),
45+
response,
46+
}
47+
},
3448
);
3549
}
3650

0 commit comments

Comments
 (0)