Commit 27de1cad by archer

fix: 短信验证码首位不能为0

parent 3ea2cf1d
...@@ -5,6 +5,8 @@ import { AuthCode } from '@/service/models/authCode'; ...@@ -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) ...@@ -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({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment