Added types to database/users
This commit is contained in:
parent
68f9bca054
commit
51a5b3b602
@ -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<string> {
|
||||
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<User> {
|
||||
return await prisma.user.findUnique({ where: { id: userId } });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user