import { BRANDING_NAME } from '@lobechat/business-const'; import { Alert, Button, Flexbox, Icon, Input, Skeleton, Text } from '@lobehub/ui'; import { Divider, Form } from 'antd'; import type { FormInstance, InputRef } from 'antd'; import { createStaticStyles } from 'antd-style'; import { ChevronRight, Mail } from 'lucide-react'; import { useEffect, useRef } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import AuthIcons from '@/components/AuthIcons'; import { PRIVACY_URL, TERMS_URL } from '@/const/url'; import AuthCard from '../../../../features/AuthCard'; const styles = createStaticStyles(({ css, cssVar }) => ({ setPasswordLink: css` cursor: pointer; color: ${cssVar.colorPrimary}; text-decoration: underline; `, })); export const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; export const USERNAME_REGEX = /^\w+$/; export interface SignInEmailStepProps { disableEmailPassword?: boolean; form: FormInstance<{ email: string }>; isSocialOnly: boolean; loading: boolean; oAuthSSOProviders: string[]; onCheckUser: (values: { email: string }) => Promise; onSetPassword: () => void; onSocialSignIn: (provider: string) => void; serverConfigInit: boolean; socialLoading: string | null; } export const SignInEmailStep = ({ disableEmailPassword, form, isSocialOnly, loading, oAuthSSOProviders, serverConfigInit, socialLoading, onCheckUser, onSetPassword, onSocialSignIn, }: SignInEmailStepProps) => { const { t } = useTranslation('auth'); const emailInputRef = useRef(null); useEffect(() => { emailInputRef.current?.focus(); }, []); const divider = ( {t('betterAuth.signin.orContinueWith')} ); const getProviderLabel = (provider: string) => { const normalized = provider .toLowerCase() .replaceAll(/(^|[_-])([a-z])/g, (_, __, c) => c.toUpperCase()); const normalizedKey = normalized.replaceAll(/[^\dA-Za-z]/g, ''); const key = `betterAuth.signin.continueWith${normalizedKey}`; return t(key, { defaultValue: `Continue with ${normalized}` }); }; const footer = ( {t('footer.terms')} ), terms: ( {t('footer.privacy')} ), }} i18nKey={'footer.agreement'} ns={'auth'} /> ); return ( {!serverConfigInit && ( {divider} )} {serverConfigInit && oAuthSSOProviders.length > 0 && ( {oAuthSSOProviders.map((provider) => ( ))} {!disableEmailPassword && divider} )} {serverConfigInit && disableEmailPassword && oAuthSSOProviders.length === 0 && ( )} {!disableEmailPassword && (
onCheckUser(values as { email: string })} > { if (!value) return Promise.resolve(); const trimmedValue = (value as string).trim(); if (EMAIL_REGEX.test(trimmedValue) || USERNAME_REGEX.test(trimmedValue)) { return Promise.resolve(); } return Promise.reject(new Error(t('betterAuth.errors.emailInvalid'))); }, }, ]} style={{ marginBottom: 0 }} > } ref={emailInputRef} size="large" style={{ padding: 6, }} suffix={