From e5759f5a6f9a07eb65074c2ba1b96b5cc818c7d7 Mon Sep 17 00:00:00 2001 From: qikongjian Date: Sun, 21 Sep 2025 12:37:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=B7=E6=AD=8C=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 5 ++++- .env.production | 7 ++++++- app/api/auth/google/callback/route.ts | 4 ++-- lib/auth.ts | 24 ++++-------------------- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.env.development b/.env.development index 8e8d382..e1bc4f8 100644 --- a/.env.development +++ b/.env.development @@ -4,4 +4,7 @@ NEXT_PUBLIC_BASE_URL = https://77.smartvideo.py.qikongjian.com NEXT_PUBLIC_CUT_URL = https://77.smartcut.py.qikongjian.com # 失败率 -NEXT_PUBLIC_ERROR_CONFIG = 0.1 \ No newline at end of file +NEXT_PUBLIC_ERROR_CONFIG = 0.1 +# Google OAuth配置 +NEXT_PUBLIC_GOOGLE_CLIENT_ID=847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com +NEXT_PUBLIC_GOOGLE_REDIRECT_URI=https://www.movieflow.net/api/auth/google/callback diff --git a/.env.production b/.env.production index 1c3f3c1..cf5acab 100644 --- a/.env.production +++ b/.env.production @@ -6,9 +6,14 @@ NEXT_PUBLIC_CUT_URL = https://77.smartcut.py.qikongjian.com # NEXT_PUBLIC_JAVA_URL = https://auth.movieflow.ai # NEXT_PUBLIC_BASE_URL = https://api.video.movieflow.ai # NEXT_PUBLIC_CUT_URL = https://smartcut.movieflow.ai - +#NEXT_PUBLIC_GOOGLE_REDIRECT_URI=https://www.movieflow.ai/api/auth/google/callback # 当前域名配置 NEXT_PUBLIC_FRONTEND_URL = https://www.movieflow.ai # 失败率配置 NEXT_PUBLIC_ERROR_CONFIG = 0.2 + +# Google OAuth配置 +NEXT_PUBLIC_GOOGLE_CLIENT_ID=847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com +NEXT_PUBLIC_GOOGLE_REDIRECT_URI=https://www.movieflow.net/api/auth/google/callback + diff --git a/app/api/auth/google/callback/route.ts b/app/api/auth/google/callback/route.ts index 7ffaa18..f7264c5 100644 --- a/app/api/auth/google/callback/route.ts +++ b/app/api/auth/google/callback/route.ts @@ -87,8 +87,8 @@ export async function POST(request: NextRequest) { }); // 第一步:使用authorization code向Google换取access token和id_token - const googleClientId = '847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com'; - const googleClientSecret = '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'; // 需要设置环境变量 + const googleClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com'; + const googleClientSecret = process.env.GOOGLE_CLIENT_SECRET || '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'; if (!googleClientSecret) { console.error('Google Client Secret未配置'); diff --git a/lib/auth.ts b/lib/auth.ts index 07aa2e7..658f7e2 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -185,8 +185,8 @@ export const authFetch = async (url: string, options: RequestInit = {}) => { // Google OAuth相关函数 -// Google Client ID -const GOOGLE_CLIENT_ID = '847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com'; +// Google Client ID - 从环境变量获取 +const GOOGLE_CLIENT_ID = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID || '847079918888-o1nne8d3ij80dn20qurivo987pv07225.apps.googleusercontent.com'; /** * 初始化Google GSI SDK @@ -246,24 +246,8 @@ export const signInWithGoogle = async (inviteCode?: string): Promise => { nonce: nonce }; - // 根据环境确定正确的redirect_uri - const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; - const isDevEnv = window.location.hostname.includes('movieflow.net'); - const isProdEnv = window.location.hostname.includes('movieflow.ai'); - - let redirectUri; - redirectUri = 'https://www.movieflow.net/api/auth/google/callback'; - // if (isLocalhost) { - // // 本地开发环境:仍然使用本地地址,但后端会转发到测试环境处理 - // redirectUri = `${window.location.origin}/api/auth/google/callback`; - // } else if (isDevEnv) { - // // 指向正确的API端点 - // } else if (isProdEnv) { - // redirectUri = 'https://www.movieflow.ai/api/auth/google/callback'; // 指向正确的API端点 - // } else { - // // 默认使用生产环境 - // redirectUri = 'https://www.movieflow.ai/api/auth/google/callback'; // 指向正确的API端点 - // } + // 根据环境变量确定redirect_uri + const redirectUri = process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI || 'https://www.movieflow.ai/api/auth/google/callback'; console.log('使用的redirect_uri:', redirectUri);