change credentials to be used with the new auth library
This commit is contained in:
@@ -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 = ?'
|
||||
|
||||
Reference in New Issue
Block a user