2025-01-15 17:13:22 +03:00

38 lines
980 B
TypeScript

'use server';
import { authOptions } from '@/config/auth';
import { getCustomer, updateCustomerProfile } from '@repo/graphql/api';
import { type CustomerInput } 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);
if (session) {
const { user } = session;
const customer = await getCustomer({ telegramId: user?.telegramId });
if (customer) {
await updateCustomerProfile({
data: input,
documentId: customer.documentId,
});
}
}
revalidatePath('/profile');
}