From e02a52dfff8117f3b45a46ed28ddd35a1855d6d0 Mon Sep 17 00:00:00 2001 From: Zixin Zhou Date: Sat, 20 Sep 2025 21:27:50 +0800 Subject: [PATCH] updates google login --- app/api/auth/google/callback/route.ts | 8 ++++---- docs/testsh/test-final-verification.js | 12 ++++++------ docs/testsh/test-oauth-detailed.js | 4 ++-- lib/auth.ts | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/api/auth/google/callback/route.ts b/app/api/auth/google/callback/route.ts index a938e27..da87e7d 100644 --- a/app/api/auth/google/callback/route.ts +++ b/app/api/auth/google/callback/route.ts @@ -162,14 +162,14 @@ function getRedirectUri(request: NextRequest): string { const protocol = request.headers.get('x-forwarded-proto') || 'https'; if (host.includes('localhost') || host.includes('127.0.0.1')) { - return `${protocol}://${host}/users/oauth/callback`; + return `${protocol}://${host}/api/auth/google/callback`; } else if (host.includes('movieflow.net')) { - return 'https://www.movieflow.net/users/oauth/callback'; + return 'https://www.movieflow.net/api/auth/google/callback'; } else if (host.includes('movieflow.ai')) { - return 'https://www.movieflow.ai/users/oauth/callback'; + return 'https://www.movieflow.ai/api/auth/google/callback'; } else { // 默认使用生产环境 - return 'https://www.movieflow.ai/users/oauth/callback'; + return 'https://www.movieflow.ai/api/auth/google/callback'; } } diff --git a/docs/testsh/test-final-verification.js b/docs/testsh/test-final-verification.js index 7ea6cbf..74d3c08 100644 --- a/docs/testsh/test-final-verification.js +++ b/docs/testsh/test-final-verification.js @@ -120,7 +120,7 @@ async function simulateUserJourney() { // 模拟环境检测 const hostname = 'www.movieflow.net'; const isDevEnv = hostname.includes('movieflow.net'); - const redirectUri = isDevEnv ? 'https://www.movieflow.net/users/oauth/callback' : 'https://www.movieflow.ai/users/oauth/callback'; + const redirectUri = isDevEnv ? 'https://www.movieflow.net/api/auth/google/callback' : 'https://www.movieflow.ai/api/auth/google/callback'; logSuccess(`🔄 构建授权URL,redirect_uri: ${redirectUri}`); journey.push({ @@ -140,11 +140,11 @@ async function simulateUserJourney() { }); // 步骤4: Google重定向回应用 - logInfo('🔄 Google重定向到 /users/oauth/callback?code=xxx&state=xxx'); + logInfo('🔄 Google重定向到 /api/auth/google/callback?code=xxx&state=xxx'); journey.push({ step: 4, action: 'Google重定向回调', - callbackUrl: '/users/oauth/callback', + callbackUrl: '/api/auth/google/callback', status: 'success' }); @@ -203,9 +203,9 @@ async function checkPotentialIssues() { // 2. Google Console配置检查 logInfo('需要在Google Console中配置以下redirect_uri:'); const redirectUris = [ - 'https://www.movieflow.net/users/oauth/callback', - 'https://www.movieflow.ai/users/oauth/callback', - 'http://localhost:3000/users/oauth/callback' + 'https://www.movieflow.net/api/auth/google/callback', + 'https://www.movieflow.ai/api/auth/google/callback', + 'http://localhost:3000/api/auth/google/callback' ]; redirectUris.forEach(uri => { diff --git a/docs/testsh/test-oauth-detailed.js b/docs/testsh/test-oauth-detailed.js index 10b960a..1a4c55a 100644 --- a/docs/testsh/test-oauth-detailed.js +++ b/docs/testsh/test-oauth-detailed.js @@ -85,7 +85,7 @@ async function simulateCompleteOAuthFlow() { let redirectUri; if (isDevEnv) { - redirectUri = 'https://www.movieflow.net/users/oauth/callback'; + redirectUri = 'https://www.movieflow.net/api/auth/google/callback'; } logSuccess(`环境检测: ${hostname} → DevEnv: ${isDevEnv}`); @@ -270,7 +270,7 @@ async function simulateCompleteOAuthFlow() { code: mockAuthCode, client_id: CONFIG.GOOGLE_CLIENT_ID, client_secret: CONFIG.GOOGLE_CLIENT_SECRET, - redirect_uri: 'https://www.movieflow.net/users/oauth/callback', + redirect_uri: 'https://www.movieflow.net/api/auth/google/callback', grant_type: 'authorization_code', }); diff --git a/lib/auth.ts b/lib/auth.ts index e149fb1..8c727dc 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -253,14 +253,14 @@ export const signInWithGoogle = async (inviteCode?: string): Promise => { let redirectUri; if (isLocalhost) { - redirectUri = `${window.location.origin}/users/oauth/callback`; + redirectUri = `${window.location.origin}/api/auth/google/callback`; } else if (isDevEnv) { - redirectUri = 'https://www.movieflow.net/users/oauth/callback'; // 修正:指向正确的Next.js页面路由 + redirectUri = 'https://www.movieflow.net/api/auth/google/callback'; // 指向正确的API端点 } else if (isProdEnv) { - redirectUri = 'https://www.movieflow.ai/users/oauth/callback'; // 修正:指向正确的Next.js页面路由 + redirectUri = 'https://www.movieflow.ai/api/auth/google/callback'; // 指向正确的API端点 } else { // 默认使用生产环境 - redirectUri = 'https://www.movieflow.ai/users/oauth/callback'; // 修正:指向正确的Next.js页面路由 + redirectUri = 'https://www.movieflow.ai/api/auth/google/callback'; // 指向正确的API端点 } console.log('使用的redirect_uri:', redirectUri);