again shiiiit!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
This commit is contained in:
@@ -60,7 +60,7 @@ export default function UserProfilePage() {
|
|||||||
fetchUser();
|
fetchUser();
|
||||||
}, [reset]);
|
}, [reset]);
|
||||||
|
|
||||||
const onSubmit: SubmitHandler<UserProfileFormValues> = async (data) => {
|
const onSubmit: SubmitHandler<UserProfileFormValues> = (data) => {
|
||||||
startSavingTransition(async () => {
|
startSavingTransition(async () => {
|
||||||
const result = await updateUser({
|
const result = await updateUser({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
@@ -73,7 +73,6 @@ export default function UserProfilePage() {
|
|||||||
title: "Profile Updated",
|
title: "Profile Updated",
|
||||||
description: "Your profile has been updated successfully.",
|
description: "Your profile has been updated successfully.",
|
||||||
});
|
});
|
||||||
// Clear password fields and reset dirty state after successful submission
|
|
||||||
reset({ ...data, password: '', confirmPassword: '' });
|
reset({ ...data, password: '', confirmPassword: '' });
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export async function updateUser(
|
|||||||
data: z.infer<typeof UserUpdateSchema>
|
data: z.infer<typeof UserUpdateSchema>
|
||||||
): Promise<{ success: boolean; error?: string }> {
|
): Promise<{ success: boolean; error?: string }> {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (!session?.user?.id) {
|
if (!session || !session.user || !session.user.id) {
|
||||||
return { success: false, error: 'Not authenticated. Please log in again.' };
|
return { success: false, error: 'Not authenticated. Please log in again.' };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,17 +44,17 @@ export async function updateUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { name, email, password } = validated.data;
|
const { name, email, password } = validated.data;
|
||||||
|
const userId = session.user.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// In a real application, you should hash the password!
|
|
||||||
if (password && password.trim().length > 0) {
|
if (password && password.trim().length > 0) {
|
||||||
const stmt = db.prepare(
|
const stmt = db.prepare(
|
||||||
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
|
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
|
||||||
);
|
);
|
||||||
stmt.run(name, email, password, session.user.id);
|
stmt.run(name, email, password, userId);
|
||||||
} else {
|
} else {
|
||||||
const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?');
|
const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?');
|
||||||
stmt.run(name, email, session.user.id);
|
stmt.run(name, email, userId);
|
||||||
}
|
}
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user