Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export async function updateProfileInfo(state, formData) {
- const session = await auth();
- if (!session || !session.user) {
- return { ...state, error: "Not authorized", status: "ERROR" }
- }
- const formValues = {
- name: formData.name,
- email: formData.email,
- address: formData.address,
- city: formData.city
- }
- if (!formValues.name || !formValues.email) {
- return { ...state, error: "Name and Email are required!", status: "ERROR" }
- }
- try {
- const user = await prisma.user.update({
- where: {
- id: session.user.id
- },
- data: formValues
- })
- revalidatePath("/profile");
- return { ...state, status: "SUCCESS", data: user };
- } catch (error) {
- console.error("Error updating profile: ", error);
- return { ...state, error: "An unexpected error occurred", status: "ERROR" };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment