import { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useGetStartupConfig } from 'librechat-data-provider/react-query'; import { GoogleIcon, FacebookIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components'; import { useAuthContext } from '~/hooks/AuthContext'; import { ThemeSelector } from '~/components/ui'; import SocialButton from './SocialButton'; import { getLoginError } from '~/utils'; import { useLocalize } from '~/hooks'; import LoginForm from './LoginForm'; function Login() { const { login, error, isAuthenticated } = useAuthContext(); const { data: startupConfig } = useGetStartupConfig(); const localize = useLocalize(); const navigate = useNavigate(); useEffect(() => { if (isAuthenticated) { navigate('/c/new', { replace: true }); } }, [isAuthenticated, navigate]); if (!startupConfig) { return null; } const socialLogins = startupConfig.socialLogins ?? []; const providerComponents = { discord: ( ), facebook: ( ), github: ( ), google: ( ), openid: ( startupConfig.openidImageUrl ? ( ) : ( ) } label={startupConfig.openidLabel} id="openid" /> ), }; const privacyPolicy = startupConfig.interface?.privacyPolicy; const termsOfService = startupConfig.interface?.termsOfService; const privacyPolicyRender = privacyPolicy?.externalUrl && ( {localize('com_ui_privacy_policy')} ); const termsOfServiceRender = termsOfService?.externalUrl && ( {localize('com_ui_terms_of_service')} ); return ( {localize('com_auth_welcome_back')} {error && ( {localize(getLoginError(error))} )} {startupConfig.emailLoginEnabled && } {startupConfig.registrationEnabled && ( {' '} {localize('com_auth_no_account')}{' '} {localize('com_auth_sign_up')} )} {startupConfig.socialLoginEnabled && ( <> {startupConfig.emailLoginEnabled && ( <> Or > )} {socialLogins.map((provider) => providerComponents[provider] || null)} > )} {privacyPolicyRender} {privacyPolicyRender && termsOfServiceRender && ( )} {termsOfServiceRender} ); } export default Login;
{' '} {localize('com_auth_no_account')}{' '} {localize('com_auth_sign_up')}