1
0
forked from Yara724/api

Moved OTP to SMS module

This commit is contained in:
SepehrYahyaee
2026-05-09 12:36:38 +03:30
parent 9e2cec5bc3
commit 74c91c73b6
7 changed files with 10 additions and 21 deletions

View File

@@ -1,8 +0,0 @@
import { Module } from "@nestjs/common";
import { OtpService } from "./otp.service";
@Module({
providers: [OtpService],
exports: [OtpService],
})
export class OtpModule {}

View File

@@ -1,16 +0,0 @@
import { Injectable } from "@nestjs/common";
// import crypto from "crypto"
const crypto = require("node:crypto");
@Injectable()
export class OtpService {
createDigit(digits: number): string {
const max = Math.pow(10, digits);
const randomBytes = crypto.randomBytes(Math.ceil(digits / 2));
const randomNumber = parseInt(randomBytes.toString("hex"), 16) % max;
return randomNumber.toString().padStart(digits, "0");
}
create() {
return this.createDigit(5);
}
}