Skip to content

Commit

Permalink
feat : add update user photo
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedrinvits committed Oct 6, 2024
1 parent c3a88ca commit 2fe856b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions data/updateUserPhoto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use server"
import { db } from "@/lib/db";
import { auth } from "../auth";
import { getUserByEmail,getUserById } from "./user";

export const updateUserPhoto = async (
profileImageUrl : string,
) => {
try {
// Autenticação para obter a sessão e o ID do usuário
const session = await auth();
const authorId = session?.id;

// Obtenção do usuário pelo e-mail
const user = await getUserById(parseInt(authorId));

if (!user) {
throw new Error('Usuário não encontrado.');
}

// Atualizando as informações do usuário no banco de dados
const updatedUser = await db.user.update({
where: { id: user.id }, // Atualiza o usuário baseado no ID
data: {
profileImageUrl
},
});
return { success: "foto alterada com sucesso!", error: null };

} catch (error) {
console.error('Erro ao atualizar as informações:', error);
return { success: null, error: "Erro ao atualizar as informações." };
}
};

0 comments on commit 2fe856b

Please sign in to comment.