Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
27de1cad
authored
Apr 21, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 短信验证码首位不能为0
parent
3ea2cf1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
4 deletions
+3
-4
src/pages/api/user/sendAuthCode.ts
+3
-4
No files found.
src/pages/api/user/sendAuthCode.ts
View file @
27de1cad
...
@@ -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
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment