change credentials to be used with the new auth library

This commit is contained in:
Leon Serfaty G
2025-07-17 11:50:07 +00:00
parent 3791c0faf6
commit e5d3f49363
2 changed files with 12 additions and 11 deletions
-1
View File
@@ -78,7 +78,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.",
}); });
// Reset form to new values and clear password fields
reset({ ...data, password: '', confirmPassword: '' }); reset({ ...data, password: '', confirmPassword: '' });
} else { } else {
toast({ toast({
+7 -5
View File
@@ -1,9 +1,10 @@
'use server'; 'use server';
import db from '@/lib/db'; import db from '@/lib/db';
import type { User } from '@/lib/types'; import type { User as DbUser } from '@/lib/types';
import { z } from 'zod'; import { z } from 'zod';
import { auth } from '@/lib/auth'; import { auth } from '@/app/api/auth/[...nextauth]/route';
const UserUpdateSchema = z.object({ const UserUpdateSchema = z.object({
name: z.string().min(1, 'Name is required'), name: z.string().min(1, 'Name is required'),
@@ -11,14 +12,16 @@ const UserUpdateSchema = z.object({
password: z.string().optional(), password: z.string().optional(),
}); });
export async function getUser(): Promise<(User & { id: string }) | null> { type UserWithId = DbUser & { id: string };
export async function getUser(): Promise<UserWithId | null> {
const session = await auth(); const session = await auth();
if (!session?.user?.id) { if (!session?.user?.id) {
return null; return null;
} }
try { try {
const stmt = db.prepare('SELECT id, name, email FROM users WHERE id = ?'); const stmt = db.prepare('SELECT id, name, email FROM users WHERE id = ?');
const user = stmt.get(session.user.id) as User | undefined; const user = stmt.get(session.user.id) as DbUser | undefined;
if (!user) return null; if (!user) return null;
return { ...user, id: user.id.toString() }; return { ...user, id: user.id.toString() };
} catch (error) { } catch (error) {
@@ -46,7 +49,6 @@ export async function updateUser(
const userId = session.user.id; const userId = session.user.id;
try { try {
// Note: In a real production app, password should be hashed!
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 = ?'