diff --git a/app.py b/app.py
index 9c245948..6efa9116 100755
--- a/app.py
+++ b/app.py
@@ -4637,50 +4637,15 @@ def wechat_callback():
update_wechat_session(state, {'status': new_status, 'user_info': {'user_id': user.id}})
print(f"✅ 微信扫码状态已更新: {new_status}, user_id: {user.id}")
- # ⚡ PC 扫码模式:返回简单页面,不重定向(避免 iframe 导航整个页面)
- # 前端会通过轮询检测到状态变化,自动关闭弹窗
- return '''
-
-
-
-
- 授权成功
-
-
-
-
-
-
- ''', 200
+ # ⚡ PC 扫码模式:重定向到前端回调页面
+ # 微信扫码登录会跳转整个页面,所以需要重定向到前端处理
+ pc_redirect_params = urllib.parse.urlencode({
+ 'wechat_login': 'success',
+ 'state': state,
+ 'is_new_user': '1' if is_new_user else '0',
+ })
+ print(f"✅ PC 微信登录成功,重定向到前端回调页面")
+ return redirect(f"/home/wechat-callback?{pc_redirect_params}")
except Exception as e:
print(f"❌ 微信登录失败: {e}")
@@ -4692,50 +4657,8 @@ def wechat_callback():
if wechat_session_exists(state):
update_wechat_session(state, {'status': 'auth_failed', 'error': str(e)})
- # ⚡ 返回错误页面,不重定向
- return '''
-
-
-
-
- 授权失败
-
-
-
-
-
-
- ''', 200
+ # ⚡ 重定向到首页并显示错误
+ return redirect('/home?error=wechat_login_failed')
@app.route('/api/auth/login/wechat', methods=['POST'])
diff --git a/src/components/Auth/WechatRegister.js b/src/components/Auth/WechatRegister.js
index 57adab1a..d11a4a1f 100644
--- a/src/components/Auth/WechatRegister.js
+++ b/src/components/Auth/WechatRegister.js
@@ -492,7 +492,7 @@ export default function WechatRegister() {
width="300"
height="350"
scrolling="no"
- sandbox="allow-scripts allow-same-origin allow-forms allow-popups"
+ sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation"
allow="clipboard-write"
style={{
border: 'none',