From 0a7d9c75c0efb87d10b0fd4d1e8e16ac67c93751 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 13 Jan 2025 20:03:01 +0300 Subject: [PATCH] add action getProfile --- apps/web/actions/profile.ts | 14 ++++++++++++++ apps/web/app/(main)/profile/page.tsx | 24 ++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/web/actions/profile.ts b/apps/web/actions/profile.ts index ec39e9a..dd59307 100644 --- a/apps/web/actions/profile.ts +++ b/apps/web/actions/profile.ts @@ -5,6 +5,20 @@ import { type CustomerInput, type Enum_Customer_Role } from '@repo/graphql/types import { getServerSession } from 'next-auth/next'; import { revalidatePath } from 'next/cache'; +export async function getProfile() { + const session = await getServerSession(authOptions); + + if (session) { + const { user } = session; + const customer = await getCustomer({ telegramId: user?.telegramId }); + if (customer) { + return customer; + } + } + + return null; +} + export async function updateProfile(input: CustomerInput) { const session = await getServerSession(authOptions); diff --git a/apps/web/app/(main)/profile/page.tsx b/apps/web/app/(main)/profile/page.tsx index 68d75cc..8d4e3ea 100644 --- a/apps/web/app/(main)/profile/page.tsx +++ b/apps/web/app/(main)/profile/page.tsx @@ -1,27 +1,23 @@ -import { updateProfile, updateRole } from '@/actions/profile'; +import { getProfile, updateProfile, updateRole } from '@/actions/profile'; import { CheckboxWithText } from '@/components/profile/checkbox-with-text'; import { ProfileField } from '@/components/profile/profile-field'; -import { authOptions } from '@/config/auth'; -import { getCustomer } from '@repo/graphql/api'; import { Avatar, AvatarFallback, AvatarImage } from '@repo/ui/components/ui/avatar'; import { Card, CardContent, CardHeader } from '@repo/ui/components/ui/card'; -import { getServerSession } from 'next-auth/next'; export default async function ProfilePage() { - const session = await getServerSession(authOptions); - const user = await getCustomer({ telegramId: session?.user?.telegramId }); - const photoUrl = user?.photoUrl ?? 'https://github.com/shadcn.png'; + const customer = await getProfile(); + const photoUrl = customer?.photoUrl ?? 'https://github.com/shadcn.png'; - if (!user) return 'Профиль не найден'; + if (!customer) return 'Пользователь не найден. Зарегистрируйтесь с помощью бота.'; return ( - - {user?.name.charAt(0)} + + {customer?.name.charAt(0)} -

{user?.name}

+

{customer?.name}

- +