Skip to content

Commit

Permalink
refactor: rename signin to login
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyoptimist committed Jun 14, 2024
1 parent 2e2b8c5 commit 93f12d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Body, Post, Get, Request } from '@nestjs/common';
import { ApiResponse, ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { SigninDto } from './dto/signin.dto';
import { LoginDto } from './dto/login.dto';
import { SignupDto } from './dto/signup.dto';
import { UserService } from '@modules/user/user.service';
import { IRequest } from '@modules/user/user.interface';
Expand All @@ -20,8 +20,8 @@ export class AuthController {
@ApiResponse({ status: 201, description: 'Successful Login' })
@ApiResponse({ status: 400, description: 'Bad Request' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async login(@Body() signinDto: SigninDto): Promise<any> {
const user = await this.authService.validateUser(signinDto);
async login(@Body() dto: LoginDto): Promise<any> {
const user = await this.authService.validateUser(dto);
return this.authService.createToken(user);
}

Expand Down
8 changes: 4 additions & 4 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigService } from '@nestjs/config';
import { Hash } from '@app/utils/hash.util';
import { UserService } from '@modules/user/user.service';
import { IUser } from '@modules/user/user.interface';
import { SigninDto } from './dto/signin.dto';
import { LoginDto } from './dto/login.dto';
import { JwtPayload } from './passport/jwt.strategy';

@Injectable()
Expand All @@ -16,13 +16,13 @@ export class AuthService {
private readonly userService: UserService,
) {}

async validateUser(signinDto: SigninDto): Promise<IUser> {
const user = await this.userService.findByEmail(signinDto.email);
async validateUser(dto: LoginDto): Promise<IUser> {
const user = await this.userService.findByEmail(dto.email);
if (!user) {
throw new UnauthorizedException('User not found.');
}

const isPasswordValid = Hash.compare(signinDto.password, user.password);
const isPasswordValid = Hash.compare(dto.password, user.password);
if (!isPasswordValid) {
throw new UnauthorizedException('Wrong password.');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, MinLength } from 'class-validator';

export class SigninDto {
export class LoginDto {
@ApiProperty({
required: true,
})
Expand Down

0 comments on commit 93f12d7

Please sign in to comment.