From 60abedee4158f5f5918a81461d8c48df66c77241 Mon Sep 17 00:00:00 2001 From: scffs Date: Sun, 10 Dec 2023 01:55:51 +0700 Subject: [PATCH] lint --- apps/api/src/handlers/authHandler.ts | 6 +++--- apps/api/src/routes/auth/authRoutes.ts | 8 +++++-- apps/api/src/services/authService.ts | 30 +++++++++++++++----------- package.json | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/apps/api/src/handlers/authHandler.ts b/apps/api/src/handlers/authHandler.ts index 21c5c65..1b69968 100644 --- a/apps/api/src/handlers/authHandler.ts +++ b/apps/api/src/handlers/authHandler.ts @@ -1,5 +1,5 @@ -import { ApiResponse, ContextWith } from '../types' import { authenticateUser } from '@services' +import { ApiResponse, ContextWith } from '../types' interface Body { password: string @@ -31,12 +31,12 @@ export const postAuth = async ({ }) const verify = await jwt.verify(cookie.auth) - + console.debug('verify', verify) console.debug('cookie.auth', cookie.auth) console.debug('success', success) return { - success, + success } } diff --git a/apps/api/src/routes/auth/authRoutes.ts b/apps/api/src/routes/auth/authRoutes.ts index a425883..1a991c2 100644 --- a/apps/api/src/routes/auth/authRoutes.ts +++ b/apps/api/src/routes/auth/authRoutes.ts @@ -1,7 +1,7 @@ import { postAuth } from '@handlers' +import { getUserById } from '@services' import Elysia, { t } from 'elysia' import { authBody } from './authSchema' -import { getUserById } from '@services' const app = new Elysia().post('/auth', postAuth, { body: t.Object(authBody), @@ -9,7 +9,11 @@ const app = new Elysia().post('/auth', postAuth, { beforeHandle: async (context) => { const user = await getUserById(context.body.id) - if (!user || user.id !== context.body.id || user.login !== context.body.login) { + if ( + !user || + user.id !== context.body.id || + user.login !== context.body.login + ) { context.set.status = 400 return 'Bad request' } diff --git a/apps/api/src/services/authService.ts b/apps/api/src/services/authService.ts index fdf43e4..ad6839a 100644 --- a/apps/api/src/services/authService.ts +++ b/apps/api/src/services/authService.ts @@ -1,39 +1,43 @@ +import { PrismaClient } from '@prisma/client' import { comparePassword } from '@utils' import { ApiResponse } from '../types' -import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() export const authenticateUser = async ( id: number, login: string, - password: string, + password: string ): Promise> => { - console.log(id) - console.log(password) - console.log(login) const user = await prisma.user.findUnique({ where: { email: login, id - }, + } }) - + + // FIXME: мб удалить, т.к. на уровне мидлвара мы будем уверены в существовании юзера + if (!user) { + return { + success: false + } + } + const isValidPassword = await comparePassword( password, - user!.salt, - user!.password, + user.salt, + user.password ) - + if (!isValidPassword) { return { success: false, - data: 'Invalid password', + data: 'Invalid password' } } - + return { success: true, - data: 'Password', + data: 'Password' } } diff --git a/package.json b/package.json index 845d36e..65cfe44 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dev:startDB": "cd apps/api && bun db:start", "lint": "biome lint . --apply", "format": "biome format . --write", - "checkAll": "biome check . --apply", + "checkAll": "biome check . --apply-unsafe", "build:web": "cd apps/web && bun run build", "build:api": "cd apps/api && bun run build", "build:api:types": "cd apps/api && bun run build:types"