diff --git a/apps/web/app/(auth)/telegram/page.tsx b/apps/web/app/(auth)/telegram/page.tsx index aed1db0..38ca5e7 100644 --- a/apps/web/app/(auth)/telegram/page.tsx +++ b/apps/web/app/(auth)/telegram/page.tsx @@ -1,5 +1,5 @@ 'use client'; -import { updateProfile } from '@/actions/profile'; +import { getProfile, updateProfile } from '@/actions/profile'; import { LoadingSpinner } from '@repo/ui/components/ui/spinner'; import { initData, isMiniAppDark, useSignal } from '@telegram-apps/sdk-react'; import { signIn, useSession } from 'next-auth/react'; @@ -22,13 +22,27 @@ export default function Auth() { await updateProfile({ photoUrl: initDataUser.photoUrl }); } - await updateProfile({ active: true }); + const customer = await getProfile({ telegramId: initDataUser?.id }); + + if (!customer?.active) { + await updateProfile({ + active: true, + name: `${initDataUser?.firstName || ''} + ' ' + ${initDataUser?.lastName}`.trim(), + }); + } setIsUpdating(false); }; update(); - }, [initDataUser?.photoUrl, isDark, setTheme]); + }, [ + initDataUser?.firstName, + initDataUser?.id, + initDataUser?.lastName, + initDataUser?.photoUrl, + isDark, + setTheme, + ]); useEffect(() => { if (isUpdating) return;