fix: 短信验证码首位不能为0
This commit is contained in:
parent
3ea2cf1dcb
commit
27de1cad47
@ -5,6 +5,8 @@ import { AuthCode } from '@/service/models/authCode';
|
|||||||
import { connectToDatabase } from '@/service/mongo';
|
import { connectToDatabase } from '@/service/mongo';
|
||||||
import { sendPhoneCode, sendEmailCode } from '@/service/utils/sendNote';
|
import { sendPhoneCode, sendEmailCode } from '@/service/utils/sendNote';
|
||||||
import { UserAuthTypeEnum } from '@/constants/common';
|
import { UserAuthTypeEnum } from '@/constants/common';
|
||||||
|
import { customAlphabet } from 'nanoid';
|
||||||
|
const nanoid = customAlphabet('123456789', 6);
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
try {
|
try {
|
||||||
@ -16,10 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
|
|
||||||
await connectToDatabase();
|
await connectToDatabase();
|
||||||
|
|
||||||
let code = '';
|
const code = nanoid();
|
||||||
for (let i = 0; i < 6; i++) {
|
|
||||||
code += Math.floor(Math.random() * 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断 1 分钟内是否有重复数据
|
// 判断 1 分钟内是否有重复数据
|
||||||
const authCode = await AuthCode.findOne({
|
const authCode = await AuthCode.findOne({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user