-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3a88ca
commit 2fe856b
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." }; | ||
} | ||
}; |