all
This commit is contained in:
1 parent
90125aede9
commit
2d6c29a1f3
404 files changed
+126983
-85
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { Body, Controller, Inject, Post } from "@nestjs/common";
|
||||
import type { LoginInput } from "../../dtos/auth.dto.js";
|
||||
import {
|
||||
AUTH_SERVICE,
|
||||
type IAuthService,
|
||||
} from "./interfaces/auth-service.interface.js";
|
||||
|
||||
@Controller("auth")
|
||||
export class AuthController {
|
||||
constructor(
|
||||
@Inject(AUTH_SERVICE) private readonly authService: IAuthService,
|
||||
) {}
|
||||
|
||||
@Post("login")
|
||||
login(@Body() body: LoginInput) {
|
||||
return this.authService.login(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { UserModule } from "../user/user.module.js";
|
||||
import { AuthController } from "./auth.controller.js";
|
||||
import { AuthService } from "./auth.service.js";
|
||||
import { AUTH_SERVICE } from "./interfaces/auth-service.interface.js";
|
||||
|
||||
@Module({
|
||||
imports: [UserModule],
|
||||
controllers: [AuthController],
|
||||
providers: [{ provide: AUTH_SERVICE, useClass: AuthService }],
|
||||
})
|
||||
export class AuthModule {}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Inject, Injectable, UnauthorizedException } from "@nestjs/common";
|
||||
import type { LoginInput } from "../../dtos/auth.dto.js";
|
||||
import type { User } from "../../entities/user.entity.js";
|
||||
import {
|
||||
USER_SERVICE,
|
||||
type IUserService,
|
||||
} from "../user/interfaces/user-service.interface.js";
|
||||
import type { IAuthService } from "./interfaces/auth-service.interface.js";
|
||||
|
||||
@Injectable()
|
||||
export class AuthService implements IAuthService {
|
||||
constructor(
|
||||
@Inject(USER_SERVICE) private readonly userService: IUserService,
|
||||
) {}
|
||||
|
||||
async login({ id, password }: LoginInput): Promise<User> {
|
||||
const user = await this.userService.verifyCredentials({ id, password });
|
||||
if (!user) {
|
||||
throw new UnauthorizedException("Credenciales inválidas");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { LoginInput } from "../../../dtos/auth.dto.js";
|
||||
import type { User } from "../../../entities/user.entity.js";
|
||||
|
||||
export const AUTH_SERVICE = Symbol("AUTH_SERVICE");
|
||||
|
||||
export interface IAuthService {
|
||||
login(input: LoginInput): Promise<User>;
|
||||
}
|
||||
Reference in new issue
Block a user