From 0e46c54971dc8f0d39932a3e24b2495f5dc3dc5d Mon Sep 17 00:00:00 2001 From: qikongjian Date: Mon, 22 Sep 2025 11:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=B7=E6=AD=8C=E7=99=BB=E5=BD=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E4=BF=A1=E6=81=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/users/oauth/callback/page.tsx | 10 ++++++++-- lib/auth.ts | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/users/oauth/callback/page.tsx b/app/users/oauth/callback/page.tsx index 7777e2a..1776d5d 100644 --- a/app/users/oauth/callback/page.tsx +++ b/app/users/oauth/callback/page.tsx @@ -16,7 +16,13 @@ export default function OAuthCallback() { useEffect(() => { const handleOAuthCallback = async () => { try { - console.log('OAuth回调页面开始处理...'); + console.log('🎯 Google OAuth 回调页面开始处理...'); + console.log('📍 回调页面调试信息:'); + console.log(' - 完整回调 URL:', window.location.href); + console.log(' - 回调域名:', window.location.hostname); + console.log(' - 回调协议:', window.location.protocol); + console.log(' - 回调路径:', window.location.pathname); + console.log(' - URL 查询参数:', window.location.search); // 获取URL参数 const params: OAuthCallbackParams = { @@ -26,7 +32,7 @@ export default function OAuthCallback() { error_description: searchParams.get("error_description") || undefined, }; - console.log('获取到的URL参数:', params); + console.log('📦 获取到的URL参数:', params); // 检查是否有错误 if (params.error) { diff --git a/lib/auth.ts b/lib/auth.ts index 658f7e2..ea449ff 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -249,7 +249,15 @@ export const signInWithGoogle = async (inviteCode?: string): Promise => { // 根据环境变量确定redirect_uri const redirectUri = process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI || 'https://www.movieflow.ai/api/auth/google/callback'; - console.log('使用的redirect_uri:', redirectUri); + // 详细的调试日志 + console.log('🔍 Google OAuth 调试信息:'); + console.log(' - 当前域名:', window.location.hostname); + console.log(' - 当前协议:', window.location.protocol); + console.log(' - 当前端口:', window.location.port); + console.log(' - 完整 origin:', window.location.origin); + console.log(' - 环境变量 NEXT_PUBLIC_GOOGLE_REDIRECT_URI:', process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI); + console.log(' - 最终使用的 redirect_uri:', redirectUri); + console.log(' - Google Client ID:', GOOGLE_CLIENT_ID); // 构建Google OAuth2授权URL(Medium风格参数) const authParams = new URLSearchParams({ @@ -265,7 +273,16 @@ export const signInWithGoogle = async (inviteCode?: string): Promise => { const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?${authParams.toString()}`; - console.log('跳转到Google授权页面:', authUrl); + console.log('📤 发送给 Google 的完整授权 URL:'); + console.log(authUrl); + console.log('📋 URL 参数解析:'); + authParams.forEach((value, key) => { + if (key === 'state') { + console.log(` - ${key}: ${JSON.stringify(JSON.parse(value), null, 2)}`); + } else { + console.log(` - ${key}: ${value}`); + } + }); // 保存state到sessionStorage用于验证 sessionStorage.setItem('google_oauth_state', JSON.stringify({