test massage

This commit is contained in:
2026-05-13 18:48:38 +03:30
parent d417fe6366
commit 5fc120becd
4 changed files with 123 additions and 2 deletions
+21 -1
View File
@@ -1,6 +1,7 @@
import {
BadRequestException,
Injectable,
ServiceUnavailableException,
UnauthorizedException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
@@ -13,6 +14,7 @@ import { UserEntity, UserRole } from '../../entities/user.entity';
import { JwtPayload } from './auth.types';
import { RequestOtpDto } from './dto/request-otp.dto';
import { VerifyOtpDto } from './dto/verify-otp.dto';
import { SmsService } from './sms.service';
type RequestOtpResponse = {
expiresInSeconds: number;
@@ -32,6 +34,7 @@ export class AuthService {
constructor(
private readonly config: ConfigService,
private readonly jwt: JwtService,
private readonly sms: SmsService,
@InjectRepository(AuthOtpEntity)
private readonly otps: Repository<AuthOtpEntity>,
@InjectRepository(UserEntity)
@@ -59,11 +62,28 @@ export class AuthService {
}),
);
const returnOtpInResponse =
this.config.get<string>('AUTH_RETURN_OTP') === 'true';
if (!returnOtpInResponse) {
if (!this.sms.isConfigured()) {
throw new BadRequestException(
'SMS is not configured. Set SMS_USERNAME, SMS_PASSWORD (or SMS_API_KEY), and SMS_SENDER.',
);
}
const sent = await this.sms.sendOtpSms(mobile, code);
if (!sent) {
throw new ServiceUnavailableException(
'Could not send SMS. Please try again later.',
);
}
}
const response: RequestOtpResponse = {
expiresInSeconds: this.otpTtlSeconds,
};
if (this.config.get<string>('AUTH_RETURN_OTP') === 'true') {
if (returnOtpInResponse) {
response.otpCode = code;
}