diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 9ba4b78..45f5182 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -3,7 +3,7 @@ import { useNavigate, useLocation, useSearchParams } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useQuery } from '@tanstack/react-query' import { useAuthStore } from '../store/auth' -import { brandingApi, getCachedBranding, setCachedBranding, preloadLogo, isLogoPreloaded, type BrandingInfo } from '../api/branding' +import { brandingApi, getCachedBranding, setCachedBranding, preloadLogo, isLogoPreloaded, type BrandingInfo, type EmailAuthEnabled } from '../api/branding' import { getAndClearReturnUrl } from '../utils/token' import LanguageSwitcher from '../components/LanguageSwitcher' import TelegramLoginButton from '../components/TelegramLoginButton' @@ -65,7 +65,29 @@ export default function Login() { initialData: cachedBranding ?? undefined, }) + // Check if email auth is enabled + const { data: emailAuthConfig } = useQuery({ + queryKey: ['email-auth-enabled'], + queryFn: brandingApi.getEmailAuthEnabled, + staleTime: 60000, + }) + const isEmailAuthEnabled = emailAuthConfig?.enabled ?? true + const botUsername = import.meta.env.VITE_TELEGRAM_BOT_USERNAME || '' + + // If email auth is disabled but user came with ref param, redirect to bot + useEffect(() => { + if (referralCode && emailAuthConfig?.enabled === false && botUsername) { + window.location.href = `https://t.me/${botUsername}?start=ref_${referralCode}` + } + }, [referralCode, emailAuthConfig, botUsername]) + + // If email auth is disabled but we initially set to email tab, switch back to telegram + useEffect(() => { + if (!isEmailAuthEnabled && activeTab === 'email') { + setActiveTab('telegram') + } + }, [isEmailAuthEnabled, activeTab]) const appName = branding ? branding.name : (import.meta.env.VITE_APP_NAME || 'VPN') const appLogo = branding?.logo_letter || import.meta.env.VITE_APP_LOGO || 'V' const logoUrl = branding ? brandingApi.getLogoUrl(branding) : null @@ -202,8 +224,8 @@ export default function Login() { {t('auth.loginSubtitle')}

- {/* Referral Banner */} - {referralCode && ( + {/* Referral Banner - only show when email auth is enabled */} + {referralCode && isEmailAuthEnabled && (
@@ -247,28 +269,34 @@ export default function Login() { /* Card */
{/* Tabs */} -
- - -
+ {isEmailAuthEnabled ? ( +
+ + +
+ ) : ( +
+

Telegram

+
+ )} {error && (
@@ -276,7 +304,7 @@ export default function Login() {
)} - {activeTab === 'telegram' ? ( + {activeTab === 'telegram' || !isEmailAuthEnabled ? (

{t('auth.registerHint')} diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 1916490..fb2aa67 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -6,7 +6,7 @@ import { useAuthStore } from '../store/auth' import { authApi } from '../api/auth' import { notificationsApi, NotificationSettings, NotificationSettingsUpdate } from '../api/notifications' import { referralApi } from '../api/referral' -import { brandingApi } from '../api/branding' +import { brandingApi, type EmailAuthEnabled } from '../api/branding' // Icons const CopyIcon = () => ( @@ -63,6 +63,14 @@ export default function Profile() { staleTime: 60000, }) + // Check if email auth is enabled + const { data: emailAuthConfig } = useQuery({ + queryKey: ['email-auth-enabled'], + queryFn: brandingApi.getEmailAuthEnabled, + staleTime: 60000, + }) + const isEmailAuthEnabled = emailAuthConfig?.enabled ?? true + // Build referral link for cabinet const referralLink = referralInfo?.referral_code ? `${window.location.origin}/login?ref=${referralInfo.referral_code}` @@ -258,7 +266,8 @@ export default function Profile() {

)} - {/* Email Section */} + {/* Email Section - only show when email auth is enabled */} + {isEmailAuthEnabled && (

{t('profile.emailAuth')}

@@ -381,6 +390,7 @@ export default function Profile() {
)}
+ )} {/* Notification Settings */}