diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/profile/DeleteAccount.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/profile/DeleteAccount.tsx index 0d4ece1b1c..49ae6e6f85 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/profile/DeleteAccount.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/profile/DeleteAccount.tsx @@ -3,14 +3,13 @@ import DeleteDialog from "@/components/shared/DeleteDialog"; import AvatarPlaceholder from "@/images/avatar-placeholder.png"; import { formbricksLogout } from "@/lib/formbricks"; -import { TProfile } from "@formbricks/types/v1/profile"; import { Button, Input, ProfileAvatar } from "@formbricks/ui"; import { Session } from "next-auth"; import { signOut } from "next-auth/react"; import Image from "next/image"; import { Dispatch, SetStateAction, useState } from "react"; import toast from "react-hot-toast"; -import { profileDeleteAction } from "./actions"; +import { deleteProfileAction } from "./actions"; export function EditAvatar({ session }) { return ( @@ -38,10 +37,9 @@ interface DeleteAccountModalProps { open: boolean; setOpen: Dispatch>; session: Session; - profile: TProfile; } -function DeleteAccountModal({ setOpen, open, session, profile }: DeleteAccountModalProps) { +function DeleteAccountModal({ setOpen, open, session }: DeleteAccountModalProps) { const [deleting, setDeleting] = useState(false); const [inputValue, setInputValue] = useState(""); @@ -52,7 +50,7 @@ function DeleteAccountModal({ setOpen, open, session, profile }: DeleteAccountMo const deleteAccount = async () => { try { setDeleting(true); - await profileDeleteAction(profile.id); + await deleteProfileAction(); await signOut(); await formbricksLogout(); } catch (error) { @@ -105,7 +103,7 @@ function DeleteAccountModal({ setOpen, open, session, profile }: DeleteAccountMo ); } -export function DeleteAccount({ session, profile }: { session: Session | null; profile: TProfile }) { +export function DeleteAccount({ session }: { session: Session | null }) { const [isModalOpen, setModalOpen] = useState(false); if (!session) { @@ -114,7 +112,7 @@ export function DeleteAccount({ session, profile }: { session: Session | null; p return (
- +

Delete your account with all personal data. This cannot be undone!

diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/profile/EditName.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/profile/EditName.tsx index 97e8e5f45a..a4a523b0e6 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/profile/EditName.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/profile/EditName.tsx @@ -3,7 +3,7 @@ import { Button, Input, Label } from "@formbricks/ui"; import { useForm } from "react-hook-form"; import toast from "react-hot-toast"; -import { profileEditAction } from "./actions"; +import { updateProfileAction } from "./actions"; import { TProfile } from "@formbricks/types/v1/profile"; export function EditName({ profile }: { profile: TProfile }) { @@ -19,7 +19,7 @@ export function EditName({ profile }: { profile: TProfile }) { className="w-full max-w-sm items-center" onSubmit={handleSubmit(async (data) => { try { - await profileEditAction(profile.id, data); + await updateProfileAction(data); toast.success("Your name was updated successfully."); } catch (error) { toast.error(`Error: ${error.message}`); diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/profile/actions.ts b/apps/web/app/(app)/environments/[environmentId]/settings/profile/actions.ts index 35109c294e..c1cd181fbc 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/profile/actions.ts +++ b/apps/web/app/(app)/environments/[environmentId]/settings/profile/actions.ts @@ -1,12 +1,21 @@ "use server"; +import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions"; import { updateProfile, deleteProfile } from "@formbricks/lib/services/profile"; import { TProfileUpdateInput } from "@formbricks/types/v1/profile"; +import { getServerSession } from "next-auth"; +import { AuthorizationError } from "@formbricks/types/v1/errors"; -export async function profileEditAction(userId: string, data: Partial) { - return await updateProfile(userId, data); +export async function updateProfileAction(data: Partial) { + const session = await getServerSession(authOptions); + if (!session) throw new AuthorizationError("Not authorized"); + + return await updateProfile(session.user.id, data); } -export async function profileDeleteAction(userId: string) { - return await deleteProfile(userId); +export async function deleteProfileAction() { + const session = await getServerSession(authOptions); + if (!session) throw new AuthorizationError("Not authorized"); + + return await deleteProfile(session.user.id); } diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/profile/page.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/profile/page.tsx index 6c54272d4f..f3811fc6af 100644 --- a/apps/web/app/(app)/environments/[environmentId]/settings/profile/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/settings/profile/page.tsx @@ -28,7 +28,7 @@ export default async function ProfileSettingsPage() { - +
)} diff --git a/apps/web/app/(app)/onboarding/actions.ts b/apps/web/app/(app)/onboarding/actions.ts index fede75d3bc..89537f0007 100644 --- a/apps/web/app/(app)/onboarding/actions.ts +++ b/apps/web/app/(app)/onboarding/actions.ts @@ -1,12 +1,18 @@ "use server"; +import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions"; import { updateProduct } from "@formbricks/lib/services/product"; import { updateProfile } from "@formbricks/lib/services/profile"; import { TProductUpdateInput } from "@formbricks/types/v1/product"; import { TProfileUpdateInput } from "@formbricks/types/v1/profile"; +import { getServerSession } from "next-auth"; +import { AuthorizationError } from "@formbricks/types/v1/errors"; -export async function updateProfileAction(personId: string, updatedProfile: Partial) { - return await updateProfile(personId, updatedProfile); +export async function updateProfileAction(updatedProfile: Partial) { + const session = await getServerSession(authOptions); + if (!session) throw new AuthorizationError("Not authorized"); + + return await updateProfile(session.user.id, updatedProfile); } export async function updateProductAction(productId: string, updatedProduct: Partial) { diff --git a/apps/web/app/(app)/onboarding/components/Objective.tsx b/apps/web/app/(app)/onboarding/components/Objective.tsx index 7cbb7c58a3..c69bd36c85 100644 --- a/apps/web/app/(app)/onboarding/components/Objective.tsx +++ b/apps/web/app/(app)/onboarding/components/Objective.tsx @@ -42,7 +42,7 @@ const Objective: React.FC = ({ next, skip, formbricksResponseId, try { setIsProfileUpdating(true); const updatedProfile = { ...profile, objective: selectedObjective.id }; - await updateProfileAction(profile.id, updatedProfile); + await updateProfileAction(updatedProfile); setIsProfileUpdating(false); } catch (e) { setIsProfileUpdating(false); diff --git a/apps/web/app/(app)/onboarding/components/Onboarding.tsx b/apps/web/app/(app)/onboarding/components/Onboarding.tsx index 7eb5e8894c..c4f75ec5a4 100644 --- a/apps/web/app/(app)/onboarding/components/Onboarding.tsx +++ b/apps/web/app/(app)/onboarding/components/Onboarding.tsx @@ -54,7 +54,7 @@ export default function Onboarding({ session, environmentId, profile, product }: try { const updatedProfile = { ...profile, onboardingCompleted: true }; - await updateProfileAction(profile.id, updatedProfile); + await updateProfileAction(updatedProfile); if (environmentId) { router.push(`/environments/${environmentId}/surveys`); diff --git a/apps/web/app/(app)/onboarding/components/Role.tsx b/apps/web/app/(app)/onboarding/components/Role.tsx index 3817524d42..ad4e24e60e 100644 --- a/apps/web/app/(app)/onboarding/components/Role.tsx +++ b/apps/web/app/(app)/onboarding/components/Role.tsx @@ -40,7 +40,7 @@ const Role: React.FC = ({ next, skip, setFormbricksResponseId, profil try { setIsUpdating(true); const updatedProfile = { ...profile, role: selectedRole.id }; - await updateProfileAction(profile.id, updatedProfile); + await updateProfileAction(updatedProfile); setIsUpdating(false); } catch (e) { setIsUpdating(false); diff --git a/packages/lib/services/profile.ts b/packages/lib/services/profile.ts index f11cbc4efe..dc6e4d8dc5 100644 --- a/packages/lib/services/profile.ts +++ b/packages/lib/services/profile.ts @@ -116,6 +116,7 @@ export const updateProfile = async ( id: personId, }, data: data, + select: responseSelection, }); revalidateTag(getProfileByEmailCacheTag(updatedProfile.email)); @@ -137,6 +138,7 @@ const deleteUser = async (userId: string): Promise => { where: { id: userId, }, + select: responseSelection, }); revalidateTag(getProfileByEmailCacheTag(profile.email)); revalidateTag(getProfileCacheTag(userId));