From 92fb4e368738323b9a385b90abb83f1d8f822dd3 Mon Sep 17 00:00:00 2001 From: Milky0217 Date: Fri, 24 Apr 2026 11:01:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20web=5Flogin=5Fconfirm=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=94=B9=E4=B8=BA=E7=B2=BE=E7=A1=AE=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=20code=EF=BC=8C=E4=BF=AE=E5=A4=8D=20unwrap=5For(None)=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/auth.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/handlers/auth.rs b/src/handlers/auth.rs index 4d5f240..a78b0b2 100644 --- a/src/handlers/auth.rs +++ b/src/handlers/auth.rs @@ -7,7 +7,7 @@ use tracing::{debug, error, info, warn}; use crate::auth::{generate_token, generate_refresh_token, verify_refresh_token}; use crate::db; -use crate::error::ErrorResponse; +use crate::error::{AppError, ErrorResponse}; use crate::models::Claims; use crate::models::{ AppState, LoginResponse, RefreshTokenRequest, TokenRefreshResponse, @@ -472,13 +472,15 @@ pub async fn web_login_confirm( let short_code = req.code.trim(); // 查找登录码(模糊匹配,因为存入的是 ASD-XXXXXX 格式) - let record: Option<(String, String, chrono::DateTime, Option)> = sqlx::query_as( - "SELECT code, openid, expires_at, user_id FROM web_login_codes WHERE code LIKE $1", - ) - .bind(format!("%{}%", short_code)) - .fetch_optional(pool.get_ref()) - .await - .unwrap_or(None); + let record: Option<(String, String, chrono::DateTime, Option)> = + sqlx::query_as( + "SELECT code, openid, expires_at, user_id FROM web_login_codes WHERE code = $1", + ) + .bind(short_code) + .fetch_optional(pool.get_ref()) + .await + .ok() + .flatten(); let (code, openid, expires_at, existing_user_id) = match record { Some(r) => r,