feat: add otp code verification

This commit is contained in:
Sergey Krylov 2026-01-24 15:34:09 +03:00
parent 153c9f7503
commit 353213c6bd
5 changed files with 59 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import { Body, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common'
import { ApiOperation } from '@nestjs/swagger' import { ApiOperation } from '@nestjs/swagger'
import { AuthClientGrpc } from './auth.grpc' import { AuthClientGrpc } from './auth.grpc'
import { SendOtpRequestDto } from './dto' import { SendOtpRequestDto, VerifyOtpRequestDto } from './dto'
@Controller('auth') @Controller('auth')
export class AuthController { export class AuthController {
@ -17,4 +17,14 @@ export class AuthController {
public sendOtp(@Body() dto: SendOtpRequestDto) { public sendOtp(@Body() dto: SendOtpRequestDto) {
return this.client.sendOtp(dto) return this.client.sendOtp(dto)
} }
@ApiOperation({
summary: 'Verify OTP',
description: 'Verify code to the user phone or email'
})
@Post('otp/verify')
@HttpCode(HttpStatus.OK)
public verifyOtp(@Body() dto: VerifyOtpRequestDto) {
return this.client.verifyOtp(dto)
}
} }

View File

@ -2,7 +2,8 @@ import { Inject, Injectable, OnModuleInit } from '@nestjs/common'
import type { ClientGrpc } from '@nestjs/microservices' import type { ClientGrpc } from '@nestjs/microservices'
import { import {
AuthServiceClient, AuthServiceClient,
SendOtpRequest SendOtpRequest,
VerifyOtpRequest
} from '@teacinema/contracts/gen/auth' } from '@teacinema/contracts/gen/auth'
@Injectable() @Injectable()
@ -18,4 +19,8 @@ export class AuthClientGrpc implements OnModuleInit {
public sendOtp(request: SendOtpRequest) { public sendOtp(request: SendOtpRequest) {
return this.authService.sendOtp(request) return this.authService.sendOtp(request)
} }
public verifyOtp(request: VerifyOtpRequest) {
return this.authService.verifyOtp(request)
}
} }

View File

@ -1 +1,2 @@
export * from './send-otp.request.dto' export * from './send-otp.request.dto'
export * from './verify-otp.request.dto'

View File

@ -0,0 +1,38 @@
import { ApiProperty } from '@nestjs/swagger'
import {
IsEnum,
IsNotEmpty,
IsNumberString,
IsString,
Length,
Validate
} from 'class-validator'
import { IdentifierValidator } from '../../../../shared/validators'
export class VerifyOtpRequestDto {
@ApiProperty({
description: 'User phone or email',
example: '+791234567890'
})
@Validate(IdentifierValidator)
@IsString()
public identifier: string
@ApiProperty({
description: 'Otp code',
example: '123456'
})
@IsNumberString()
@IsNotEmpty()
@Length(6, 6)
public code: string
@ApiProperty({
description: 'Type of identifier',
example: 'phone',
enum: ['phone', 'email']
})
@IsEnum(['phone', 'email'])
public type: 'phone' | 'email'
}

View File

@ -1193,9 +1193,9 @@
"@sinonjs/commons" "^3.0.1" "@sinonjs/commons" "^3.0.1"
"@teacinema/contracts@^1.0.0": "@teacinema/contracts@^1.0.0":
version "1.0.0" version "1.0.1"
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.0.0/contracts-1.0.0.tgz#9395c331ec94b604d1946d26b683dd93e04a6225" resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.0.1/contracts-1.0.1.tgz#25021fecb1d33d0505fd11ca3d8201660cb1bcbe"
integrity sha512-zhYE0SIWjJl+ujp+yf0dT3ua4hWpR19gy//CwVcLO9bvfh+bZRYttlXE6XXWGucHv6208+sNNdkpwSwVyKyqNg== integrity sha512-gvdbQ3Xowr4/h9Kq2P+pO2lr9vyWvIvRoU74mG3LSq2IiKKuwQUTxRaJnzI5MdtNqiq0WIUMo30cfqnBzNAJ1A==
dependencies: dependencies:
"@nestjs/microservices" "^11.1.12" "@nestjs/microservices" "^11.1.12"
protoc "33.4.0" protoc "33.4.0"