diff --git a/src/lib/database/users.ts b/src/lib/database/users.ts index 7e5cc481e..af7d11d3a 100644 --- a/src/lib/database/users.ts +++ b/src/lib/database/users.ts @@ -6,11 +6,26 @@ import { asyncExecShell, uniqueName } from '$lib/common'; import * as db from '$lib/database'; import { startCoolifyProxy } from '$lib/haproxy'; -export async function hashPassword(password: string) { +import type { User } from '@prisma/client'; + +export async function hashPassword(password: string): Promise { const saltRounds = 15; return bcrypt.hash(password, saltRounds); } -export async function login({ email, password, isLogin }) { + +export async function login({ + email, + password, + isLogin +}: { + email: string; + password: string; + isLogin: boolean; +}): Promise<{ + status: number; + headers: { 'Set-Cookie': string }; + body: { userId: string; teamId: string; permission: string; isAdmin: boolean }; +}> { const users = await prisma.user.count(); const userFound = await prisma.user.findUnique({ where: { email }, @@ -52,7 +67,7 @@ export async function login({ email, password, isLogin }) { if (userFound) { if (userFound.type === 'email') { - const passwordMatch = await bcrypt.compare(password, userFound.password); + const passwordMatch = bcrypt.compare(password, userFound.password); if (!passwordMatch) { throw { error: 'Wrong password or email address.' @@ -124,6 +139,6 @@ export async function login({ email, password, isLogin }) { }; } -export async function getUser({ userId }) { +export async function getUser({ userId }: { userId: string }): Promise { return await prisma.user.findUnique({ where: { id: userId } }); }