feat: add profile link to header and implement user profile update functionality with email and password management

This commit is contained in:
Julien Froidefond
2025-11-27 13:37:18 +01:00
parent 10ff15392f
commit 873b3dd9f3
7 changed files with 417 additions and 0 deletions

58
src/actions/profile.ts Normal file
View File

@@ -0,0 +1,58 @@
'use server';
import { auth } from '@/lib/auth';
import { updateUserProfile, updateUserPassword, getUserById } from '@/services/auth';
export async function getProfileAction() {
const session = await auth();
if (!session?.user?.id) {
return { success: false, error: 'Non authentifié', data: null };
}
const user = await getUserById(session.user.id);
if (!user) {
return { success: false, error: 'Utilisateur non trouvé', data: null };
}
return {
success: true,
data: {
id: user.id,
name: user.name,
email: user.email,
createdAt: user.createdAt,
},
};
}
export async function updateProfileAction(data: { name?: string; email?: string }) {
const session = await auth();
if (!session?.user?.id) {
return { success: false, error: 'Non authentifié' };
}
const result = await updateUserProfile(session.user.id, data);
return result;
}
export async function updatePasswordAction(data: {
currentPassword: string;
newPassword: string;
}) {
const session = await auth();
if (!session?.user?.id) {
return { success: false, error: 'Non authentifié' };
}
if (data.newPassword.length < 6) {
return { success: false, error: 'Le nouveau mot de passe doit faire au moins 6 caractères' };
}
const result = await updateUserPassword(
session.user.id,
data.currentPassword,
data.newPassword
);
return result;
}