diff --git a/src/pages/login/apis/index.ts b/src/pages/login/apis/index.ts index cfb70c7e..29ca034e 100644 --- a/src/pages/login/apis/index.ts +++ b/src/pages/login/apis/index.ts @@ -6,7 +6,7 @@ import qs from 'query-string'; export const AUTH_API = '/auth'; -export const AUTH_CONFIG_API = '/auth-config'; +export const AUTH_CONFIG_API = '/auth/config'; export const AUTH_OIDC_LOGIN_API = '/auth/oidc/login'; export const AUTH_SAML_LOGIN_API = '/auth/saml/login'; @@ -52,5 +52,10 @@ export const updatePassword = async (params: any) => { }; export const fetchAuthConfig = async () => { - return request(AUTH_CONFIG_API); + return request<{ + is_saml: boolean; + is_oidc: boolean; + first_time_setup: boolean; + get_initial_password_command: string; + }>(AUTH_CONFIG_API); }; diff --git a/src/pages/login/components/local-user-form.tsx b/src/pages/login/components/local-user-form.tsx index 0a75111b..ed35920f 100644 --- a/src/pages/login/components/local-user-form.tsx +++ b/src/pages/login/components/local-user-form.tsx @@ -9,7 +9,6 @@ import { import { useIntl } from '@umijs/max'; import { Button, Checkbox, Divider, Form, FormInstance } from 'antd'; import { createStyles } from 'antd-style'; -import { GET_INITIAL_PASSWORD } from '../../login/config'; const useStyles = createStyles(({ token, css }) => { return { @@ -37,17 +36,26 @@ const useStyles = createStyles(({ token, css }) => { interface LocalUserFormProps { handleLogin: (values: any) => void; form: FormInstance; + loginOption: { + saml: boolean; + oidc: boolean; + first_time_setup: boolean; + get_initial_password_command: string; + }; } const LocalUserForm: React.FC = (props) => { - const { handleLogin, form } = props; + const { handleLogin, form, loginOption } = props; const intl = useIntl(); const { styles } = useStyles(); const renderCommandInfo = () => { + if (!loginOption?.first_time_setup) { + return null; + } return (
- +
@@ -56,8 +64,8 @@ const LocalUserForm: React.FC = (props) => {
@@ -140,6 +148,7 @@ const LocalUserForm: React.FC = (props) => { > {intl.formatMessage({ id: 'common.button.login' })} + {renderCommandInfo()} ); }; diff --git a/src/pages/login/components/login-form.tsx b/src/pages/login/components/login-form.tsx index 51280405..ed4d6144 100644 --- a/src/pages/login/components/login-form.tsx +++ b/src/pages/login/components/login-form.tsx @@ -251,7 +251,11 @@ const LoginForm = () => { {renderWelCome()} {renderLoginButtons()} {(!hasThirdPartyLogin || isPassword) && ( - + )} {hasThirdPartyLogin && isPassword && ( diff --git a/src/pages/login/hooks/use-sso-auth.ts b/src/pages/login/hooks/use-sso-auth.ts index 1649e660..c4c5a95e 100644 --- a/src/pages/login/hooks/use-sso-auth.ts +++ b/src/pages/login/hooks/use-sso-auth.ts @@ -10,6 +10,8 @@ import { type LoginOption = { saml: boolean; oidc: boolean; + first_time_setup: boolean; + get_initial_password_command: string; }; export function useSSOAuth({ @@ -25,7 +27,9 @@ export function useSSOAuth({ }) { const [loginOption, setLoginOption] = useState({ saml: false, - oidc: false + oidc: false, + first_time_setup: false, + get_initial_password_command: '' }); const intl = useIntl(); @@ -44,16 +48,17 @@ export function useSSOAuth({ const init = async () => { try { - const authConfig = await fetchAuthConfig(); + const { is_oidc, is_saml, ...rest } = await fetchAuthConfig(); setLoginOption({ - oidc: !!authConfig.is_oidc, - saml: !!authConfig.is_saml + ...rest, + oidc: !!is_oidc, + saml: !!is_saml }); if (sso) { onLoading?.(true); - if (authConfig.is_oidc) { + if (is_oidc) { oidcLogin(); - } else if (authConfig.is_saml) { + } else if (is_saml) { samlLogin(); } else { onError?.( @@ -62,7 +67,12 @@ export function useSSOAuth({ } } } catch (error: any) { - setLoginOption({ oidc: false, saml: false }); + setLoginOption({ + oidc: false, + saml: false, + first_time_setup: false, + get_initial_password_command: '' + }); onLoading?.(false); } };