排查验证码问题

This commit is contained in:
2025-04-22 10:44:05 +08:00
parent 5b3de2b714
commit 4c0fc8be6a
2 changed files with 6 additions and 0 deletions

View File

@@ -37,17 +37,21 @@ export default async function verify(props: VerifyParams): Promise<ApiResponse>
}) })
} }
catch (error) { catch (error) {
console.error('验证码验证失败:', error)
throw new Error('验证码验证失败', {cause: error}) throw new Error('验证码验证失败', {cause: error})
} }
} }
async function verifyCaptcha(userInput: string): Promise<boolean> { async function verifyCaptcha(userInput: string): Promise<boolean> {
console.log("验证验证码:", userInput)
const cookieStore = await cookies() const cookieStore = await cookies()
const hash = cookieStore.get('captcha_hash')?.value const hash = cookieStore.get('captcha_hash')?.value
const salt = cookieStore.get('captcha_salt')?.value const salt = cookieStore.get('captcha_salt')?.value
// 如果没有找到验证码cookie验证失败 // 如果没有找到验证码cookie验证失败
if (!hash || !salt) { if (!hash || !salt) {
console.log('验证码cookie不存在')
return false return false
} }
@@ -59,6 +63,7 @@ async function verifyCaptcha(userInput: string): Promise<boolean> {
// 比较哈希值 // 比较哈希值
const isValid = hash === userInputHash const isValid = hash === userInputHash
console.log('验证码验证结果:', isValid, hash, userInputHash)
// 验证后删除验证码cookie防止重复使用 // 验证后删除验证码cookie防止重复使用
if (isValid) { if (isValid) {

View File

@@ -61,6 +61,7 @@ function generateCaptchaImage(text: string) {
export async function GET(request: Request) { export async function GET(request: Request) {
const captchaText = generateCaptchaText() const captchaText = generateCaptchaText()
console.log('生成验证码:', captchaText)
// 生成验证码图像 // 生成验证码图像
const captchaImage = generateCaptchaImage(captchaText) const captchaImage = generateCaptchaImage(captchaText)