From e5d3f49363c9cbe72b32e12f29e7134a74e55238 Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Thu, 17 Jul 2025 11:50:07 +0000 Subject: [PATCH] change credentials to be used with the new auth library --- src/app/admin/settings/user/page.tsx | 11 +++++------ src/lib/actions/user.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/app/admin/settings/user/page.tsx b/src/app/admin/settings/user/page.tsx index 559091d..0a365a2 100644 --- a/src/app/admin/settings/user/page.tsx +++ b/src/app/admin/settings/user/page.tsx @@ -54,11 +54,11 @@ export default function UserProfilePage() { const fetchUser = async () => { const user = await getUser(); if (user) { - reset({ - name: user.name, - email: user.email, - password: "", - confirmPassword: "" + reset({ + name: user.name, + email: user.email, + password: "", + confirmPassword: "" }); } }; @@ -78,7 +78,6 @@ export default function UserProfilePage() { title: "Profile Updated", description: "Your profile has been updated successfully.", }); - // Reset form to new values and clear password fields reset({ ...data, password: '', confirmPassword: '' }); } else { toast({ diff --git a/src/lib/actions/user.ts b/src/lib/actions/user.ts index 644ebb8..8f0e681 100644 --- a/src/lib/actions/user.ts +++ b/src/lib/actions/user.ts @@ -1,9 +1,10 @@ + 'use server'; import db from '@/lib/db'; -import type { User } from '@/lib/types'; +import type { User as DbUser } from '@/lib/types'; import { z } from 'zod'; -import { auth } from '@/lib/auth'; +import { auth } from '@/app/api/auth/[...nextauth]/route'; const UserUpdateSchema = z.object({ name: z.string().min(1, 'Name is required'), @@ -11,14 +12,16 @@ const UserUpdateSchema = z.object({ password: z.string().optional(), }); -export async function getUser(): Promise<(User & { id: string }) | null> { +type UserWithId = DbUser & { id: string }; + +export async function getUser(): Promise { const session = await auth(); if (!session?.user?.id) { return null; } try { 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; return { ...user, id: user.id.toString() }; } catch (error) { @@ -46,7 +49,6 @@ export async function updateUser( const userId = session.user.id; try { - // Note: In a real production app, password should be hashed! if (password && password.trim().length > 0) { const stmt = db.prepare( 'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'