From 3fb25cd667b7b148a16604714f248626f1a5856d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 20 Jan 2025 18:06:43 +0300 Subject: [PATCH] update name on telegram first login --- apps/web/app/(auth)/telegram/page.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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;