From 818984d19204842efe8ad7ffcc85ac189582452f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=B3n=20Villafa=C3=B1e?= Date: Sat, 18 Apr 2026 23:24:24 -0300 Subject: [PATCH 1/2] feat(modules/auth): semi-intergation of auth module --- modules/auth/controllers/index.controller.ts | 24 ++++++++++++++++++++ modules/auth/schemas/signin.schema.ts | 9 ++++++++ 2 files changed, 33 insertions(+) create mode 100644 modules/auth/schemas/signin.schema.ts diff --git a/modules/auth/controllers/index.controller.ts b/modules/auth/controllers/index.controller.ts index b94a616..fac91cf 100644 --- a/modules/auth/controllers/index.controller.ts +++ b/modules/auth/controllers/index.controller.ts @@ -5,12 +5,14 @@ import jwt from "jsonwebtoken"; import { ZodError } from "zod"; import jwtConfig from "@/config/jwt"; +import prisma from "@/database/prisma/client"; import redisClient from "@/database/redis/client"; import NotFoundError from "../exceptions/notfound.exception"; import UnauthorizedError from "../exceptions/unauthorized.exception"; import CredentialSchema from "../schemas/credential.schema"; import RefreshTokenSchema from "../schemas/refresh-token.schema"; +import SignInSchema from "../schemas/signin.schema"; import type { JwtSubject } from "../types/jwt"; export default { @@ -87,6 +89,28 @@ export default { } }, + async signin(req: FastifyRequest, reply: FastifyReply) { + try { + const { password, ...credentials } = SignInSchema.parse(req.body); + + const userCounter = await prisma.user.count({ + where: { + email: credentials.email, + }, + }); + + if (userCounter > 0) { + throw new UnauthorizedError(req.t("Email already in use")); + } + } catch (e) { + if (e instanceof UnauthorizedError) { + reply.status(401).send({ error: e.message }); + } else { + reply.status(500).send({ error: req.t("Server error") }); + } + } + }, + logout(req: FastifyRequest, reply: FastifyReply) { try { const bearerToken = req.headers.authorization; diff --git a/modules/auth/schemas/signin.schema.ts b/modules/auth/schemas/signin.schema.ts new file mode 100644 index 0000000..495a413 --- /dev/null +++ b/modules/auth/schemas/signin.schema.ts @@ -0,0 +1,9 @@ +import { z } from "zod"; + +const SignInSchema = z.object({ + email: z.email(), + username: z.string().min(3).max(30), + password: z.string().min(8), +}); + +export default SignInSchema; From adea5ff1da2b8278350f33fc42a9e641a110866f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=B3n=20Villafa=C3=B1e?= Date: Sat, 25 Apr 2026 18:36:38 -0300 Subject: [PATCH 2/2] f --- .github/workflows/preview.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index b40ba6c..4e6e939 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -103,6 +103,9 @@ jobs: contents: read pull-requests: write steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Comment on PR env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}