Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
scffs committed Dec 9, 2023
1 parent 7e4d01d commit 60abede
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/handlers/authHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiResponse, ContextWith } from '../types'
import { authenticateUser } from '@services'
import { ApiResponse, ContextWith } from '../types'

interface Body {
password: string
Expand Down Expand Up @@ -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
}
}
8 changes: 6 additions & 2 deletions apps/api/src/routes/auth/authRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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),
// TODO: move to custom plugin (middleware)
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'
}
Expand Down
30 changes: 17 additions & 13 deletions apps/api/src/services/authService.ts
Original file line number Diff line number Diff line change
@@ -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<ApiResponse<string>> => {
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'
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 60abede

Please sign in to comment.