diff --git a/apps/admin/app/(auth)/email/register-form.tsx b/apps/admin/app/(auth)/email/register-form.tsx index 9ae0c9c..0c408e5 100644 --- a/apps/admin/app/(auth)/email/register-form.tsx +++ b/apps/admin/app/(auth)/email/register-form.tsx @@ -33,8 +33,8 @@ export default function RegisterForm({ try { const domain = email.split('@')[1]; const isValid = - !auth.email.email_enable_verify || - auth.email?.email_domain_suffix_list.split('\n').includes(domain || ''); + !auth.email.enable_verify || + auth.email?.domain_suffix_list.split('\n').includes(domain || ''); return !isValid; } catch (error) { console.log('Error checking user:', error); @@ -52,7 +52,7 @@ export default function RegisterForm({ }), password: z.string(), repeat_password: z.string(), - code: auth.email.email_enable_verify ? z.string() : z.string().nullish(), + code: auth.email.enable_verify ? z.string() : z.string().nullish(), invite: invite.forced_invite ? z.string() : z.string().nullish(), cf_token: verify.enable_register_verify && verify.turnstile_site_key @@ -120,7 +120,7 @@ export default function RegisterForm({ )} /> - {auth.email.email_enable_verify && ( + {auth.email.enable_verify && ( - {auth?.email?.email_enable_verify && ( + {auth?.email?.enable_verify && ( { - const { data } = await getOAuthByPlatform({ - platform: 'apple', + const { data } = await getAuthMethodConfig({ + method: 'apple', }); return data.data; }, }); - async function updateConfig(key: keyof API.UpdateOAuthConfig, value: unknown) { + async function updateConfig(key: keyof API.UpdataAuthMethodConfigRequest, value: unknown) { try { - await updateOAuthConfig({ + await updateAuthMethodConfig({ ...data, [key]: value, - } as API.UpdateOAuthConfig); + } as API.UpdataAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -132,8 +132,13 @@ export default function Page() { updateConfig('redirect', value)} + value={data?.config.redirect_url} + onValueBlur={(value) => + updateConfig('config', { + ...data?.config, + redirect_url: value, + }) + } /> diff --git a/apps/admin/app/dashboard/auth-control/email/page.tsx b/apps/admin/app/dashboard/auth-control/email/page.tsx index db5f9ae..dac5c70 100644 --- a/apps/admin/app/dashboard/auth-control/email/page.tsx +++ b/apps/admin/app/dashboard/auth-control/email/page.tsx @@ -1,6 +1,10 @@ 'use client'; -import { getEmailSmtpConfig, testEmailSmtp, updateEmailSmtpConfig } from '@/services/admin/system'; +import { + getAuthMethodConfig, + testEmailSend, + updateAuthMethodConfig, +} from '@/services/admin/authMethod'; import { useQuery } from '@tanstack/react-query'; import { Button } from '@workspace/ui/components/button'; import { @@ -23,14 +27,16 @@ import { toast } from 'sonner'; export default function Page() { const t = useTranslations('email'); - const ref = useRef>({}); + const ref = useRef>({}); const [email, setEmail] = useState(); const { data, refetch, isFetching } = useQuery({ - queryKey: ['getEmailSmtpConfig'], + queryKey: ['getAuthMethodConfig', 'email'], queryFn: async () => { - const { data } = await getEmailSmtpConfig(); - ref.current = data.data as API.EmailSmtpConfig; + const { data } = await getAuthMethodConfig({ + method: 'email', + }); + ref.current = data.data as API.AuthMethodConfig; return data.data; }, }); @@ -38,10 +44,10 @@ export default function Page() { async function updateConfig(key: string, value: unknown) { if (data?.[key] === value) return; try { - await updateEmailSmtpConfig({ + await updateAuthMethodConfig({ ...ref.current, [key]: value, - } as API.EmailSmtpConfig); + } as API.UpdataAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { @@ -59,94 +65,193 @@ export default function Page() { - {[ - { - key: 'email_enabled', - label: t('enable'), - description: t('enableDescription'), - component: 'switch', - }, - { - key: 'enable_email_verify', - label: t('emailVerification'), - description: t('emailVerificationDescription'), - component: 'switch', - }, - { - key: 'enable_email_domain_suffix', - label: t('emailSuffixWhitelist'), - description: t('emailSuffixWhitelistDescription'), - component: 'switch', - }, - { - key: 'email_domain_suffix_list', - label: t('whitelistSuffixes'), - description: t('whitelistSuffixesDescription'), - component: 'textarea', - }, - { - key: 'email_smtp_host', - label: t('smtpServerAddress'), - description: t('smtpServerAddressDescription'), - }, - { - key: 'email_smtp_port', - label: t('smtpServerPort'), - description: t('smtpServerPortDescription'), - type: 'number', - }, - { - key: 'email_smtp_ssl', - label: t('smtpEncryptionMethod'), - description: t('smtpEncryptionMethodDescription'), - component: 'switch', - }, - { - key: 'email_smtp_user', - label: t('smtpAccount'), - description: t('smtpAccountDescription'), - }, - { - key: 'email_smtp_pass', - label: t('smtpPassword'), - description: t('smtpPasswordDescription'), - type: 'password', - }, - { - key: 'email_smtp_from', - label: t('senderAddress'), - description: t('senderAddressDescription'), - }, - ].map(({ key, label, description, type = 'text', component = 'input' }) => ( - - - -

{description}

-
- - {component === 'input' ? ( - updateConfig(key, value)} - /> - ) : component === 'switch' ? ( - updateConfig(key, checked)} - /> - ) : ( -