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",
description: "Your profile has been updated successfully.",
});
// Reset form to new values and clear password fields
reset({ ...data, password: '', confirmPassword: '' });
} else {
toast({
+7 -5
View File
@@ -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<UserWithId | null> {
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 = ?'